x86 Assembly, Passing variable

Hi Engineers,

Another important things to understand related to function call is how the variable is passed to the function. Lets see the code below

in the code above I am going to pass 3 variable int var1, int var2 and int var3 to pass a function

we can now check the assembly in IDA as follow

As normal, all the variable shall be initilized in the main function stack frame but we can see that in the main function all the variable is accessed using ESP where the variables be access using positive because of the sub esp, 20h, it make esp pointing to lower memory address. where if EBP as the reference then it will using minus number.

Let jump to the passing variable. We can see that all the 3 varible is move backward toward the function signature void pass(int var1, int var2, int var3) where var3 is processed for the first time and var2 and the last is var1. it is the convetion of passing the variable will be read from the right to the left.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s