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

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

问题描述

此描述适用于 Linux 32 位:当 Linux 程序开始时,所有指向命令行参数的指针都存储在堆栈中.参数个数存放在0(%ebp),程序名存放在4(%ebp),参数从8(%ebp)开始存放.

我需要相同的 64 位信息.

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

<前>.globl _start_开始:popq %rcx # 这是 argc,一个参数必须是 2cmpq $2,%rcxjne usage_exitaddq $8,%rsp # 跳过 argv[0]popq %rsi # 获取 argv[1]称呼 ......}

看起来参数在堆栈上.由于这段代码不清楚,所以我问了这个问题.我猜我可以将 rsp 保持在 rbp,然后使用 0(%rbp)、8(%rbp)、16(%rbp) 等访问这些参数.这是正确的吗?

解决方案

它看起来像 3.4 Process Initialization 部分,特别是图 3.9,在已经提到的 System V AMD64 ABI 准确描述了您想知道的内容.

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).

I need the same information for 64 bit.

Edit: I have working code sample which shows how to use argc, argv[0] and 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 ...
...
}

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?

解决方案

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天全站免登陆