Linux 64中的命令行参数 [英] Linux 64 command line parameters in Assembly

查看:189
本文介绍了Linux 64中的命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此说明适用于Linux 32位:
当Linux程序开始时,所有指向命令行参数的指针都存储在堆栈中。参数的数量存储在0(%ebp),程序的名称存储在4(%ebp),参数存储在8(%ebp)。

This description is valid for Linux 32 bit: When a Linux program begins, all pointers to command-line arguments are stored on the stack. The number of arguments is stored at 0(%ebp), the name of the program is stored at 4(%ebp), and the arguments are stored from 8(%ebp).

我需要64位的相同信息。

I need the same information for 64 bit.

编辑:
我有工作代码示例演示如何使用argc,argv [0]和argv [1]: http://cubbi.com/fibonacci/asm.html


.globl _start
_start:
    popq    %rcx        # this is argc, must be 2 for one argument
    cmpq    $2,%rcx
    jne     usage_exit
    addq    $8,%rsp     # skip argv[0]
    popq    %rsi        # get argv[1]
    call ...
...
}

看起来参数在堆栈上。因为这段代码不清楚,我问这个问题。我猜想我可以保留rsp在rbp,然后访问这些参数使用0(%rbp),8(%rbp),16(%rbp)等这是正确的?

It looks like parameters are on the stack. Since this code is not clear, I ask this question. My guess that I can keep rsp in rbp, and then access these parameters using 0(%rbp), 8(%rbp), 16(%rbp) etc. It this correct?

推荐答案

它看起来像第3.4节进程初始化,特别是图3.9,在已经提到的系统V AMD64 ABI 正确描述了您想要知道的内容。

It looks like section 3.4 Process Initialization, and specifically figure 3.9, in the already mentioned System V AMD64 ABI describes precisely what you want to know.

这篇关于Linux 64中的命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆