【问题标题】:System call access in Assembly language汇编语言中的系统调用访问
【发布时间】:2015-04-28 08:42:28
【问题描述】:

我想在 Assembly 中进行系统调用(在 linux 上)。 我有系统调用访问的问题。我用 C 代码编写:

int r= syscall(SYS_access,"file", R_OK);
if(r==0){
printf("Can read\n"); 
}

这在 C 中工作,但我不知道如何处理标志和检查返回。这是我的代码:

mov eax, 33 ;system call for access
mov ebx, namefile
mov ecx, 0 ;here is int - flag?
int 80h 
cmp eax,0 ;cmp return?
je .YES

.YES:
mov eax,4 ;write
mov ebx,1 ;terminal
mov ecx,yes ;what I write
mov edx,9 ;4
int 0x80 ;call kernel

如何修复标志并比较返回值?

【问题讨论】:

  • 这只是使用搜索引擎的问题。如果你用谷歌搜索“man access”,你会发现access在成功的情况下返回什么,如果你用谷歌搜索“#define R_OK”,你会发现R_OK对应的值。
  • 如果你知道如何用 C 编写它,那么只需编译 C 代码并查看生成的机器码!

标签: assembly system-calls


【解决方案1】:

这里是访问函数:

#define F_OK        0   /* test for existence of file */
#define X_OK        0x01    /* test for execute or search permission */
#define W_OK        0x02    /* test for write permission */
#define R_OK        0x04    /* test for read permission */

小心,这是十六进制代码,但十六进制也可以。 大多数系统调用的返回值都在 EAX 中,但不是全部。第一次使用系统调用时,一个好的经验法则是在 EAX 中查找返回值。如果不存在,则需要进一步研究。

EAX 中的访问返回。 并检查您的文件。如果您在正确的工作目录中并且您写入了正确的文件名。(您的 EBX)

【讨论】:

    猜你喜欢
    • 2020-08-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多