0

我已经将我的大脑划到了极限,并且还在网上搜索了有关 Assembly 中文件处理的信息,但我仍然对此感到困惑。我正在使用 linux shell 以 AT&T 语法创建汇编程序。基本上我不明白如何将文件名推送到 ebx。以下是让我感到困惑的代码。

    section .text
    global _start

    _start:
pop ebx     ; argc (argument count)
pop ebx     ; argv[0] (argument 0, the program name)
pop ebx     ; The first real arg, a filename

mov eax,8       ; The syscall number for creat() (we already have the filename  in ebx)
mov ecx,00644Q  ; Read/write permissions in octal (rw_rw_rw_)
int 80h     ; Call the kernel
            ; Now we have a file descriptor in eax

我不明白,将值弹出到 ebx 将如何帮助打开文件?请解释这些行。我猜这些行正在接受输入,就像我们在 C 中所做的那样{eg in main(int argc, char *argv[]) }。但我无法与之关联。

4

1 回答 1

1

参数被传递给堆栈中的其他函数。函数可以通过偏移量访问堆栈或单独弹出值来检索它们。

pop ebx
pop ebx
pop ebx

因为每个弹出操作都会覆盖ebx的值 ebx 会保留最后一个弹出的值。所以这三个指令等价于:

mov ebx, [esp+8] ; esp+0 argc, esp+4 argv, esp+8 first param
于 2013-09-22T16:18:50.573 回答