检索气体中的命令行参数
我正在努力寻找一种方法来检索 GAS 中第一个命令行参数的第一个字符。为了澄清我在这里的意思,我如何在 NASM 中做到这一点:
main:
pop ebx
pop ebx
pop ebx ; get first argument string address into EBX register
cmp byte [ebx], 45 ; compare the first char of the argument string to ASCII dash ('-', dec value 45)
...
编辑:文字转换为 AT&T 语法并在 GAS 中编译它不会产生预期的结果。 EBX 值不会被识别为字符。
I am struggling to find a way to retrieve first character of the first command line argument in GAS. To clarify what I mean here how I do it in NASM:
main:
pop ebx
pop ebx
pop ebx ; get first argument string address into EBX register
cmp byte [ebx], 45 ; compare the first char of the argument string to ASCII dash ('-', dec value 45)
...
EDIT: Literal conversion to AT&T syntax and compiling it in GAS won't produce expected results. EBX value will not be recognized as a character.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您为什么想要在 2011 年用汇编语言编写整个应用程序(除非乐趣是您的主要动机,并且编写数千条汇编语言对您来说很有趣)。
如果您这样做,您可能不想调用程序的入口点
main
(在 Gnu/Linux 上的 C 中,该函数是从 crt0.o 或类似函数调用的),但更多可能开始
。如果您想了解在汇编中启动应用程序的详细方法,请阅读汇编指南以及 x86-64 的 Linux ABI 补充 以及针对您的特定系统的类似文档。
I'm not sure to understand why you want, in 2011, to code an entire application in assembly (unless fun is your main motivation, and coding thousands of assembly lines is fun to you).
And if you do that, you probably don't want to call the entry point of your program
main
(in C on Gnu/Linux, that function is called from crt0.o or similar), but more probablystart
.And if you want to understand the detailed way of starting an application in assembly, read the Assembly Howto and the Linux ABI supplement for x86-64 and similar documents for your particular system.
好吧,我自己想出来了。入口点不应称为
main
,而应称为_start
。感谢巴塞尔的提示,+1。Ok I figured it out myself. Entry point should NOT be called
main
, but_start
. Thanks Basile for a hint, +1.