Why does main () compiled by D have a 32-bit return value on a 64-bit machine?

Here is a very small source file in D:

void main() { } 

and here is objdump disassembling the .o file:

 Disassembly of section .text._Dmain: 0000000000000000 <_Dmain>: void main() 0: 55 push %rbp 1: 48 8b ec mov %rsp,%rbp 4: 31 c0 xor %eax,%eax { 6: 5d pop %rbp 7: c3 retq 

The compiler is a DMD64 D Compiler v2.056 running on an x86_64 Linux machine.

I wonder why only 32-bit EAX is cleared, and not the whole 64-bit RAX? I assume this is the return value required in the same way as in a C program, even if it is not validated in source D.

+6
source share
1 answer
 xor %eax,%eax 

Clears all rax in x64. The operation with dword-sized registers automatically clears the upper word of the full register.

+16
source

All Articles