So I can do it with the ARM, and I know theoretically it's common practice, but I have no idea how to do it on the x86.
I'm workin with a 16bit architecture here (legacy code is like that), so bear with me.
I want to pass four values to a subroutine on the stack. So I do this
PUSH param1
PUSH param2
PUSH param3
PUSH param4
; note that each parameter is 2 bytes
now we got into the subroutine (woohoo!) and in the subroutine I backup my registers, do useful work, restore my registers, then kill the value parameters.
mySub:
PUSH AX
PUSH BX
PUSH CX
; do useful work HERE
POP CX
POP BX
POP AX
RET 8 ; blow the value params off the stack
My question is this: how do I access my parameters?! On the ARM I can just treat the stack like an array that goes backwards, so it'd be like...
LDR R1, [SP, #20]
...which says "20 bytes into the stack (added to the Stack Pointer) is where we'll find the first of our parameters...now load that into register R1"
So what is the equivalent x86 notation? Anybody know?
Thanks =)