Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22039

Why does GCC set eax to 0 before call instructions? [duplicate]

$
0
0

This question already has an answer here:

Given the following C code:

#include <stdio.h>

int main()
{
    printf("%d\n", 1);

    return 42;
}

compiled with gcc -o test test.c, I get the disassembled code with gdb test -ex 'disass main':

[…]
Dump of assembler code for function main:
   0x0000000000001139 <+0>: push   %rbp
   0x000000000000113a <+1>: mov    %rsp,%rbp
   0x000000000000113d <+4>: mov    $0x1,%esi
   0x0000000000001142 <+9>: lea    0xebb(%rip),%rdi        # 0x2004
   0x0000000000001149 <+16>:    mov    $0x0,%eax
   0x000000000000114e <+21>:    callq  0x1030 <printf@plt>
   0x0000000000001153 <+26>:    mov    $0x2a,%eax
   0x0000000000001158 <+31>:    pop    %rbp
   0x0000000000001159 <+32>:    retq   
End of assembler dump.

What is the purpose of setting eax to 0 (0x0000000000001149 <+16>: mov $0x0,%eax)?

Should you always set the eax register to 0 before executing a call instruction? If so, why?


Viewing all articles
Browse latest Browse all 22039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>