Search code examples
assemblycall

How to pass arguments in push+ret method?


If I use call,

push b
push a
call address

is valid but using call makes me confusing with address.
So I want to use push+ret method like this:

push b
push a
push address
ret

But this time, passing arguments looks not working properly.
How can I pass address with this method?


Solution

  • call address
    

    This near call instruction does 2 things:

    • It places on the stack the return address, which is the memory address directly after the call address instruction itself.
    • It transfers control to the code at address by changing the EIP register.

    Your replacement code only performs the latter operation.

    To correct the code, push a return address manually:

        push b
        push a
        push Back
        push address
        ret
    Back:
    

    This time you'll see that passing the arguments works the same.


    With this alternative method it's perfectly possible to place the Back: label anywhere you like and where it makes sense!