Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

assembly

d

Here is a very small source file in D:

void main()
{
}

and here objdump's disassembly of 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 DMD64 D Compiler v2.056 running on an x86_64 Linux machine.

What I wonder is why only 32-bit EAX is being cleared rather than the whole 64-bit RAX? I assume this is a return value, required just as in a C program even if not acknowledged in D source.

like image 363
DarenW Avatar asked Oct 21 '12 03:10

DarenW


1 Answers

xor    %eax,%eax

DOES clear the entire rax in x64. Operation on the dword sized registers automatically clear the high dword of the full register.

like image 160
Jens Björnhager Avatar answered Nov 15 '22 10:11

Jens Björnhager