Assembly 在x86 AT&;中将命令行参数视为整数;T组件
此(Linux、AT&T、Intel)x86程序旨在读入三个参数,并将最大的参数存储在%ebx中作为exist状态。当我将参数放入寄存器时,结果值似乎是字节。如何获取int值 [编辑--感谢harold在下面的评论,我想问题是如何使用Assembly 在x86 AT&;中将命令行参数视为整数;T组件,assembly,x86,intel,Assembly,X86,Intel,此(Linux、AT&T、Intel)x86程序旨在读入三个参数,并将最大的参数存储在%ebx中作为exist状态。当我将参数放入寄存器时,结果值似乎是字节。如何获取int值 [编辑--感谢harold在下面的评论,我想问题是如何使用atoi获取args的int值。] .section .text .globl _start _start: popl %edi # Get the number of arguments popl %eax
atoi
获取args的int值。]
.section .text
.globl _start
_start:
popl %edi # Get the number of arguments
popl %eax # Get the program name
popl %ebx # Get the first actual argument
movl (%ebx), %ebx # get the actual value into the register (?)
popl %ecx # ;
movl (%ecx), %ecx
popl %edx #
movl (%edx), %edx
bxcx:
cmpl %ebx,%ecx
jle bxdx
movl %ecx,%ebx
bxdx:
cmpl %ebx,%edx
jle end
movl %edx,%ebx
end:
movl $1,%eax
int $0x80
为了能够调用
atoi
,您需要链接libc。e、 g:
ld -lc foo.o
要真正拨打电话,您需要遵循cdecl呼叫约定:
atoi
的签名为
int atoi(const char *nptr);
因此,要获得第一个命令行参数的整数值,我们可以
.section .text
.globl _start
_start:
popl %edi # Get the number of arguments
popl %eax # Get the program name
call atoi # Try to read the first argument as an integer and clobber %eax with the value
什么int值?您是否在寻找与
atoi
?在程序像/a.out 5 6 7
一样运行后,命令行参数的int值——在这种情况下,退出状态应为7。因此,如果我需要类似于atoi
的东西,这是否意味着值5、6等被作为字符串读入?为了使其工作,我需要动态链接它:ld-dynamic linker/lib/ld linux.So.2-o test-lc test.o