Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 375 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is argument push order

#1
I'm learning Assembly language. What exactly is argument push order? I understand it's how arguments are pushed to the stack but **what does the *left* and *right* part mean**? Left or right of what?


Or is this merely to do with the way the command is semantically written, i.e.:

mov ebp, esp ;esp is moved into ebp, right to left.

Is this correct or could someone enlighten me?
Reply

#2
In addition to [xtofl][1]'s explanation you might like to have a look at this table of [x86 calling conventions][2]. What you'll note, with regards to argument order is that *almost all* of the arguments are pushed on right to left (rightmost argument is pushed first) with the exception of Pascal.

Another scenario xtofl doesn't cover are register arguments - some ABIs require that some arguments are in registers *as opposed to* on the stack. On a `x86_64` system, for example, the function:

int add3(int a, int b, int c)

will put arguments:

a -> rdi
b -> rsi
c -> rdx

Specifically, this would look like (Intel syntax):

mov rdi, [source-of-a]
mov rsi, [source-of-b]
mov rdx, [source-of-c]
call add3

So the registers are filled up from the register list *left to right* and then the stack is used *right to left*.

As xtofl says, it doesn't matter what you do provided the caller and the callee agree - clearly, however, if the caller and the callee *disagree* that'll cause incompatibility problems and this is actually a concern not only for assembler, but for higher level languages too - luckily, compilers largely operate right to left. For further reading, you might find the callee/caller cleanup of the stack interesting - and note how it was standardised to one method for `x86_64`.

You don't say you're using `x86` - your architecture will most certainly have a standard calling convention as working without it is difficult.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#3
The processor doesn't know 'function arguments'. Therefore when you want to write `f(a,b,c)`, you really need to push the arguments 'somewhere'.

How and where to push them is mere convention. I know that on most x86 machines, function arguments are pushed on the stack from right to left, i.e. first c, then b, then a.

push c
push b
push a
call f

Pushing to the stack would, on x86, decrease the stack 'top' with a word. Three words have been pushed, and the return address, so the called function can use `top + 1*W` for `a`, `top + 2*W` for `b` and `top + 3*W` for `c`.

You could as well establish a convention that says: first two arguments are in registers `ebx` and `ecx`, rest are on the stack. As long as the caller and callee agree, you're fine.

Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through