I have a C code.
When calling function is executed first the value 75 is pushed to the stack and then value 25 is pushed to the stack. Then return address is pushed on to the stack. Return address will be the address of the next instruction after the calling function. Right? How does the return address calculated?
Then other stuff is pushed on the stack and soething copied from sp. So sp will be pointing to the top of the stack which contains what it was set with.
Then when the called function is executed, a local variable result is created on the stack and stack will be pointing to result variable.
then values of _op1 and _op2 on the stack is referenced and value for result is computed and stored in result variable on the stack.
How is the result returned to the calling function?
Where actuslly the stack frame gets created. Is it when move sp stuff is executed? old value of sp is stored and then it is used to reference the variables on the stack but it never changes but it changes during stack operation. Finally when returning from the function sp is assigned its old value which is in store. Right?
How value of result is returned to main function?
Is it that registers get told to returns the results? Why other stuff is not generally pushed to the stack while entering a function call?
Is this part of a school assignment?
No, most compilers would push lots of parameters on the stack and then set up standard stack frames. But the C51 compiler isn't like most other compilers, because the 8051 processor is one of the worst processors this world have ever seen for use with C.
The 8051 have lousy stack handling and indirect addressing so C51 tries to convert parameters and local variables into reused global variables (which then have fixed addresses) unless a function is specifically reentrant and may need multiple copies of parameters and local variables.
So in reality, parameters are sent in registers or global variables, and the result is sent back in register(s) or global variables.
The Keil tools are so extreme that a significant amount of code generation isn't done by the compiler but instead by the linker, when the linker merges the contents from the individual object files. All to be able to optimize all variable accesses as well as possible instead of producing code with register-indirect accesses.
Whats a 8051. I use arm.
lol!!
So why did you select "C51" as your Architecture/Product?!