Function Structure and Calling Conventions
6-14
6.3 Function Structure and Calling Conventions
The C compiler imposes a strict set of rules on function calls. Except for special
run-time-support functions, any function that calls or is called by a C function
must follow these rules. Failure to adhere to these rules can disrupt the C envi-
ronment and cause a program to fail.
1 illustrates a typical function call. In this example, parameters are
passed to the function, and the function uses local variables. This example
also shows allocation of a local frame for the called function. Functions that
have
no
arguments passed on the stack
and no
local variables do not allocate
a local frame.
Figure 6
−
1. Stack Use During a Function Call
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
Caller’s local
frame
SP
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
Push Arguments,
Call Function
Return
address
Allocate
Local Frame
Before
CALL
argument
n
argument
1
FP
Old
FP
SP
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
ÉÉÉÉÉ
FP
SP
FP
Caller’s local
frame
Caller’s local
frame
Argument
n
Argument 1
Argument
n
Argument 1
Return
address
Old FP
Low
High
Local frame
Temporary
location
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...