Hardware Reference
In-Depth Information
location in the stack and can avoid this problem. Since the HCS12 does not have a dedicated
frame pointer, we will not use the term frame pointer in the following discussion.
Example 4.3
Draw the stack frame for the following program segment after the last leas 2 10,sp instruc-
tion is executed:
ldd
#$1234
pshd
ldx
#$4000
pshx
jsr
sub_xyz
sub_xyz
pshd
pshx
psy
leas
2 10, sp
Solution: The caller pushes two 16-bit words into the stack. The subroutine sub_xyz saves three
16-bit registers in the stack and allocates 10 bytes in the stack. The resultant stack frame is
shown in Figure 4.5.
4.6.1 Subroutines with Local Variables in Stack
When a subroutine has very few local variables, the subroutine can use CPU registers to
hold them (need to save these registers in the stack). However, when there are not enough
CPU registers to hold local registers, the subroutine will need to assign local variables to
the stack.
SP
10 bytes for local
variables
[Y]
$4000
$1234
Return address
$4000
$1234
Figure 4.5 Stack frame of Example 4.5
 
Search WWH ::




Custom Search