如何在汇编中返回argc
我试图在汇编中返回 argc,但程序返回 0。我在 Windows 10 上使用 GNU 2.28!
这是我的代码:
.section .text
.globl main
main:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
.globl _start
_start:
pushl 0(%esp)
call main
addl 4, %esp
movl %eax, %ebx
movl $1, %eax
int $0x80
我使用以下命令来生成我的exe:
as --32 test.s -o test.obj ld -m i386pe 测试 -o test.exe
I'm trying to return argc in assembly but the program returns 0. I'm using GNU 2.28 on Windows 10 !
There is my code:
.section .text
.globl main
main:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
.globl _start
_start:
pushl 0(%esp)
call main
addl 4, %esp
movl %eax, %ebx
movl $1, %eax
int $0x80
I'm using the following commands to generate my exe:
as --32 test.s -o test.obj ld -m i386pe test -o test.exe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MS Windows 不像 GNU Linux 那样提供指向推送到机器堆栈上的分离参数的指针。当使用命令从终端窗口启动可执行程序时,例如,
您需要使用“kernel32.dll”中的 API 函数检索命令行并自行解析。
调用 API 函数 GetCommandLine 返回指向包含整个命令的字符串的指针,以可执行文件名称(本例中为
as
)开头,以 NUL 字符结尾。当程序从资源管理器启动时,可执行文件名称可能会被完成以形成可执行文件的完整路径,例如“C:\ Program Files \ GNU utility \ as.exe”。
现在,您应该逐个字符地解析字符串,测试每个字符是否是参数分隔符(空格),考虑是否在双引号内,并计算参数数量。
您可以在我的 Windows 宏库中找到示例,位置为 GetArgCount 或 Linux 位置的示例 GetArgCount。
MS Windows doesn't provide pointers to separated arguments pushed on machine stack, as GNU Linux does. When an executable program is launched from the terminal window with command e.g.
you need to retrieve the command line using API function from "kernel32.dll" and parse it yourself.
Invokation of API function GetCommandLine returns pointer to a string which contains the entire command, starting with the executable name (
as
in this example), and ending with NUL character. When the program is launched from Explorer, the executable name may be completed to form the full path to executable, for instance"C:\Program Files\GNU utilities\as.exe"
.Now you should parse the string character by character, test each one if it's argument-separator (white space), taking into account if you're inside double quotes, and count argument numbers.
You can find examples in my macrolibraries for Windows at GetArgCount or for Linux at GetArgCount.