the code is:

.global asm0
    push    ebp
    mov ebp,esp
    mov eax,DWORD PTR [ebp+0x8]
    mov ebx,DWORD PTR [ebp+0xc]
    mov eax,ebx
    mov esp,ebp
    pop ebp

The entry is: asm0(0x2a,0x4f)

The output is: 0x4f2a

Why is the input parameters reversed?


Calling Conventions:

You may be referring to calling conventions and order of parameters being pushed. If so, here is an answer addressing as such. You can read more about calling conventions in general here.


You may also be interested in reading about endianness from the NASM documentation:

3.4.3 Character Constants

A character constant consists of a string up to eight bytes long, used in an expression context. It is treated as if it was an integer.

A character constant with more than one byte will be arranged with little-endian order in mind: if you code

mov eax,'abcd'

then the constant generated is not 0x61626364, but 0x64636261, so that if you were then to store the value into memory, it would read abcd rather than dcba. This is also the sense of character constants understood by the Pentium's CPUID instruction.

Source: https://www.nasm.us/doc/nasmdoc3.html

More research on your behalf to better understand this can be done by reading about the topic of endianness. It's confusing when you first run into it, but there are many charts like this one to help demonstrate it:

enter image description here

Image source: https://agilescientific.com/blog/2017/3/31/little-endian-is-legal

Finally, there's an excellent video from OpenSecurityTraining that does a great job of explaining endianness and order of parameters/arguments with calling conventions. Click here to view it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.