Function Structure and Calling Conventions
6-15
Run-Time Environment
6.3.1 How a Function Makes a Call
A function (parent function) performs the following tasks when it calls another
function (child function). Be aware that the ARP must be set to AR1.
1) The caller pushes the arguments on the stack in reverse order (the right-
most declared argument is pushed first, and the leftmost is pushed last).
This places the leftmost argument at the top of the stack when the function
is called.
2) The caller (parent) calls the function (child).
3) The caller presumes that upon return from the function, the ARP will be
set to AR1.
4) When the called function is complete, the caller pops the arguments off the
stack with the following instruction:
SBRK n
(
n
is the number of argument words that were pushed)
6.3.2 How a Called Function Responds
A called function (child function) must perform the following tasks. On function
entry, the ARP is presumed to be set to SP (AR1).
1) Pop the return address off the hardware stack and push it onto the soft-
ware stack.
2) Push the FP onto the software stack.
3) Allocate the local frame.
4) If the function modifies AR6 or AR7, push them on the stack. Any other
registers may be modified without preserving them.
5) Execute the code for the function.
6) If the function returns a scalar value, place in the accumulator. Load 16-bit
integer and pointer return values into the accumulator with the proper sign
extension.
7) Set the ARP to AR1.
8) Restore AR6 and/or AR7, if they were saved.
9) Deallocate the local frame.
10) Restore the FP.
11) Copy the return address from the software stack and push it onto the hard-
ware stack.
12) Return.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...