Linux X86-64程序集和printf

我正在阅读一些 linux汇编手册,并找到了使用printf()函数的想法.我需要它以二进制形式将调试原因的寄存器值输出到终端,但现在我只是尝试用文本测试该函数.

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

.data
input_prompt:
    .string "Hello,world!"

printf_format:
    .string "%5d "

printf_newline:
    .string "\n"

size:
    .long 0

.text
.globl main
main:
    pushq $input_prompt
    call  printf

    movl  $0,%eax
    ret

它由GCC编制为:

gcc tmp.S -o tmp

解决方法

Linux(和Windows) x86-64 calling convention的前几个参数不在堆栈上,而是在寄存器中

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

特别:

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

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

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...