IA 32 读取命令行参数
我正在尝试使用 IA 32 的汇编代码读取命令行参数。我在这里找到了如何执行此操作的说明 http://www.paladingrp.com/ia32.shtml。我可以使用堆栈指针来获取参数的数量,但无法获取参数的值。 这就是我想要做的:
movl 8(%esp), %edx # Move pointer to argument 1 to edx
movl (%edx), %ebx # Move value of edx to ebx
movl $1, %eax # opcode for exit system call in eax
int $0x80 # return
我得到正确的指针吗?如果是这样,我如何获得它的价值?如果不是,我如何获得正确的指针?
I am trying to read command line arguments with assembly code for IA 32. I found an explanation of how to do it here http://www.paladingrp.com/ia32.shtml. I am able to use the stack pointer to get the number of arguments but I am not able to get the value of the arguments.
Here is what I am trying to do:
movl 8(%esp), %edx # Move pointer to argument 1 to edx
movl (%edx), %ebx # Move value of edx to ebx
movl $1, %eax # opcode for exit system call in eax
int $0x80 # return
Am I getting the correct pointer? If so, how do I get the value of it? If not, how do I get the correct pointer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不会将
EDX
的值移动到EBX
(注释是不正确)。该解引用
EDX
中的指针,并将解引用的结果放入EBX
中。因此,如果您使用./a.out foo
调用程序,那么EBX
最终将是0x006f6f66 (== '\0oof' ("foo\0 " 以小尾数法表示))
。我猜这不是你想要的,但你的问题并不清楚你期望在哪里发生什么。
That doesn't move value of
EDX
toEBX
(the comment is incorrect).That dereferences pointer in
EDX
, and puts the result of dereference intoEBX
. So if you invoked your program with./a.out foo
, thenEBX
will end up being0x006f6f66 (== '\0oof' ("foo\0" in little-endian))
.I am guessing that's not what you wanted, but your question is not very clear about what you are expecting to happen where.