Trying to learn from the ground up and would appreciate some assistance making sense of the following:

// void main(){} [1]
.text._Dmain    segment
        assume  CS:.text._Dmain
_Dmain:
                push    RBP
                mov     RBP,RSP
                xor     EAX,EAX
                pop     RBP
                ret
.text._Dmain    ends
.cto

// void main(string[] args) {} [2]
.text._Dmain    segment
        assume  CS:.text._Dmain
_Dmain:
                push    RBP
                mov     RBP,RSP
                sub     RSP,010h
                xor     EAX,EAX
                leave
                ret
.text._Dm

Both segments of code deal with a minimal D program: the first taking no arguments and the second taking a string array. Information prior to the ".text_Dmain segment" in both files mirror each other with the exception of module name differences.

The first difference that jumps out at me is that the ".text._Dmain segment" in [1] properly terminates with ".text._Dmain ends" like all other segments in the file up to this point. [2] is improperly: ".text._Dm".

The second is the use of leave in [2]. If I understand correctly, leave is the exact same as:

                mov     RBP,RSP
                pop     RBP

So why do we need to mov RBP, RSP in [2] but not in [1]? I'm thinking this is because RBP contains the address of args but not sure.

Last is the .cto at the end of [1], what on earth is it and what is it used for? Why does it not exist in [2]?

Thanks,
Andrew

Reply via email to