为何%eax中一个归零调用printf之前? [英] Why is %eax zeroed before a call to printf?

查看:384
本文介绍了为何%eax中一个归零调用printf之前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图拿起一点点的x86。我编译在64位MAC用gcc -S -O0。

I am trying to pick up a little x86. I am compiling on a 64bit mac with gcc -S -O0.

code在C:

printf("%d", 1);

输出:

movl    $1, %esi
leaq    LC0(%rip), %rdi
movl    $0, %eax        ; WHY?
call    _printf

我不明白为什么'的printf'调用之前%EAX清零。由于的printf 返回打印到%EAX 中的字符数我最好的猜测是归零,以prepare它为的printf ,但我会假设的printf 必须负责得到它准备好。此外,相反,如果我把我自己的函数 INT testproc(INT P1) GCC 认为没有必要prepare %EAX 。所以,我不知道为什么 GCC 治疗的printf testproc 不同。

I do not understand why %eax is cleared to 0 before 'printf' is called. Since printf returns the number of characters printed to %eax my best guess it is zeroed out to prepare it for printf but I would have assumed that printf would have to be responsible for getting it ready. Also, in contrast, if I call my own function int testproc(int p1), gcc sees no need to prepare %eax. So I wonder why gcc treats printf and testproc differently.

推荐答案

x86_64的ABI

Register    Usage
%rax        temporary register; with variable arguments
            passes information about the number of vector
            registers used; 1st return register
...

printf的是具有可变参数的函数,以及用于矢量寄存器的数目是零。

printf is a function with variable arguments, and the number of vector registers used is zero.

这篇关于为何%eax中一个归零调用printf之前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆