Set Function Return
- A register or the stack is used to pass the function return value.
Define the function return type with the appropriate type, making explicit that such stack position or register is the return value.
... loc100(); ... void loc100() { eax = 0; return; }
⇓
... eax = loc100(); ... int loc100() { eax = 0; return eax; }
Motivation
Most processors have no built-in support for returning values in function calls, i.e., native function calls have no return type. It is a common function calling convention to use a particular processor register to pass the function return value to the caller for simple types and the processor stack for complex types. For example, in the Intel IA-32 architecture the register is used to pass integers. This is a platform-specific low-level detail, and not one of the source code, which should therefore be eliminated for proper code understanding.
Mechanics
- Change the function return type from to the appropriate type.
- Post-assign all calls to the function to the specified register or stack position.
- Add the specified register or stack position to every return statement in the function body.