Today I am going to continue writing about assembly related to function return. So basically whenever you call a function and you can expect return value which maybe returning a value from function internal process.
A function by its nature can only return one variable but if you require to return more than one variable then you should pass reference variable that link to the variable in the function caller
Lets do check return value using 1 variable. the C code will be like below
Let check the assembly code below
Following the standard convention that every return variable will be stored in EAX so that we can see that in the calclate function there is statement add eax, edx which as you know that the result of that statement will be store in the left variable where it is EAX.
We also check after the function call the next operation is to assign return value to the new varibale in main function that directly use EAX where the complete statement is mov [esp+1Ch], eax.
Lets prove it with debuger. We can see the value of EAX is now 5 where it is from 2+3. this is EAX value in calculate function
Lets check the EAX value after it return to the main function. Yes we can see EAX has values 5.
So that is it. By the standard of assembly language the return variable for function will be assigned to EAX.
I will explain the return using passing variable with reference