Compiler Support on StarCore
High Address
SP
(Current)
SP
SP |
SP |
Return |
Address |
Parameters |
3, 4, 5, ... |
Local
Variables
(if any)
Saved
Registers
Return
Address
Parameters
3, 4, 5, ...
SP |
|
Return |
|
Address | SP |
Parameters |
|
3, 4, 5, ... |
|
Parameters
3, 4, 5, ...
SP
¹ | ² | ³ | ¼ | ½ |
¹ Prior to function call
²On entry to function
³During function execution ¼ Prior to exit from function ½ On return from function
ª Calling function deallocates parameters on stack
ª
Figure 11. Typical Stack Contents During Function Execution
Therefore, for the function addvecs(), parameters x[], and y[] are passed in r0 and r1, while z[] and M are passed on the stack.
Hands On
1.Open the Ex8.c and addvecs.asm files, and familiarize yourself with the code.
2.In addvecs.asm are two constants, Z_OFFSET and M_OFFSET, whose values are not set and which are represented by question marks (???). These offsets pull z[] and M from the stack. Find the lines of code that perform this task.
3.Before the code can be built, you must assign values to Z_OFFSET and M_OFFSET. To help you to do this, Figure 12 shows the stack on entry to addvecs().
24 | Introduction to the SC140 Tools |