检索气体中的命令行参数

发布于 2024-12-12 09:45:19 字数 385 浏览 0 评论 0原文

我正在努力寻找一种方法来检索 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-12-19 09:45:20

我不确定您为什么想要在 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 probably start.

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.

沦落红尘 2024-12-19 09:45:20

好吧,我自己想出来了。入口点不应称为 main,而应称为 _start。感谢巴塞尔的提示,+1。

Ok I figured it out myself. Entry point should NOT be called main, but _start. Thanks Basile for a hint, +1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文