Linux X86-64程序集和printf

Linux X86-64程序集和printf,第1张

概述我正在阅读一些 linux汇编手册,并找到了使用printf()函数的想法.我需要它以二进制形式将调试原因的寄存器值输出到终端,但现在我只是尝试用文本测试该函数. 我被困了,因为当我使用pushq而不是pushl时出现段错误.如何更改此程序以输出字符串和二进制形式的寄存器? .datainput_prompt: .string "Hello, world!"printf_format 我正在阅读一些 linux汇编手册,并找到了使用printf()函数的想法.我需要它以二进制形式将调试原因的寄存器值输出到终端,但现在我只是尝试用文本测试该函数.

我被困了,因为当我使用pushq而不是pushl时出现段错误.如何更改此程序以输出字符串和二进制形式的寄存器?

@[email protected]_prompt: .string "Hello,world!"printf_format: .string "%5d "printf_newline: .string "\n"size: .long 0.text.globl mainmain: pushq $input_prompt call printf movl $0,%eax ret

它由GCC编制为:

@H_301_13@gcc tmp.S -o tmp解决方法 linux(和windows) x86-64 calling convention的前几个参数不在堆栈上,而是在寄存器中

见http://www.x86-64.org/documentation/abi.pdf(第20页)

特别:

If the class is MEMORY,pass the argument on the stack. If the class is INTEGER,the next available register of the sequence %rdi,%rsi,%rdx,%rcx,%r8 and %r9 is used. If the class is SSE,the next available vector register is used,the registers are taken in the order from %xmm0 to %xmm7. If the class is SSEUP,the eightbyte is passed in the next available eightbyte chunk of the last used vector register. If the class is X87,X87UP or COMPLEX_X87,it is passed in memory.

INTEGER类是适合通用寄存器的任何东西,所以你也可以用它来表示字符串指针.

总结

以上是内存溢出为你收集整理的Linux X86-64程序集和printf全部内容,希望文章能够帮你解决Linux X86-64程序集和printf所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1027862.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存