DMD generates calls to next operation

Jeroen Bollen via Digitalmars-d digitalmars-d at puremagic.com
Tue May 20 12:46:00 PDT 2014


While inspecting assembly code generated by DMD I found this
weird bit of assembly:

0000000000000000 <_Dmain>:
     0:	55                   	push   rbp
     1:	48 8b ec             	mov    rbp,rsp
     4:	48 83 ec 10          	sub    rsp,0x10
     8:	c7 45 f8 05 00 00 00 	mov    DWORD PTR [rbp-0x8],0x5
     f:	c7 45 f8 06 00 00 00 	mov    DWORD PTR [rbp-0x8],0x6
    16:	48 89 ef             	mov    rdi,rbp
    19:	e8 00 00 00 00       	call   1e <_Dmain+0x1e>
    1e:	31 c0                	xor    eax,eax
    20:	c9                   	leave
    21:	c3                   	ret
    22:	66 0f 1f 44 00 00    	nop    WORD PTR [rax+rax*1+0x0]

It seems to call/jump to the operation right after it. Why does
it do that?

Code:

void main() {
	int x = 5;
	void innerFunc() {
		import std.stdio;
		writeln(x);
	}
	x = 6;
	innerFunc();
}

Also I don't really get where it's supposed to call innerFunc. It
seems it's never mentioned inside the generated main function.


More information about the Digitalmars-d mailing list