I would like to continue on how to get return result from a function call by using reference variable pass. We can pass variable to the function that accept the memory pointer of a variable that will look like void function (int * pVariable) in this case function will receive passing variable of pointer to int variable.
Let see the C code below, We are passing 2 integers and 1 pointer to integer. we will return the value of a + b in variable c
Here is the assembly code, We can see that passing variable using reference is translated to the assembly code where passing the memory address of the varible using lea (load effective address)
we can see that varible passed to the _calculate function for c variable that it will execute lea eax, [esp+28] where it loads the passedResult variable memory address.
We can see the in the above variable, Variable C is actually pointing to the address of passedResult 0x60FEFC. We can see in the below image after the it executes the highlighted codes then the result in edx is passed to the address that C hold –> mov [eax], edx. You ca see varible in the Locals windows that is now C variable has value 5
So we can differentiate passing reference and passing object to a function where passing reference will use lea to load the effective address and passing object will just use move statement as normal assignment.