DLang/Wiki/'Hello World'/Run Code/Disassembly

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 21 02:07:35 PDT 2016


On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote:
> Code ran with expected output, but Disassembly seemed to go in 
> a loop?

What makes you think that? It's hard to tell if you don't give 
any information.

Let's do that! I'll use only naive flags and all and use radare2 
to
disassemble the main D function which is _Dmain (the entry point 
has to
launch the runtime etc... we aren't very interested in that):

$ cat >test.d <<EOF
     import std.stdio;
     void main() {
         writeln("Hello World!");
     }
EOF
$ dmd test.d
$ ./test
Hello World!
$ r2 -q -c "afr; pdf @ sym._Dmain" test
┌ (fcn) sym._Dmain 24
│   sym._Dmain ();
│           ; CALL XREF from 0x08078258 (sym.main)
│           ; DATA XREF from 0x0807825b (sym.main)
│           0x08077e70      55             push ebp
│           0x08077e71      8bec           mov ebp, esp
│           0x08077e73      b9d02b0a08     mov ecx, 
str.Hello_World_;
"Hello World!" @ 0x80a2bd0
│           0x08077e78      b80c000000     mov eax, 0xc
│           0x08077e7d      51             push ecx
│           0x08077e7e      50             push eax
│           0x08077e7f      e804000000     call
sym._D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv
│           0x08077e84      31c0           xor eax, eax
│           0x08077e86      5d             pop ebp
└           0x08077e87      c3             ret

No loop. Not even a jump. I'm in x86 so arguments are simply 
pushed on the
stack. No brainer.


More information about the Digitalmars-d-learn mailing list