Page 346 - Programming Microcontrollers in C
P. 346
Digital Signal Processor Operations 331
The code in lines 16 through 20 above saves the values of xdata
and ydata in xp and yp respectively. The operations shown in lines
21 through 24 save the 8-bit value found in the B register to the
16-bit location at x+OFST-2. To be certain that the value is not
corrupted by some garbage value in the A register, the clra instruc
tion is inserted prior to the time that the value is saved.
Stack Contents
SP after ais #-6
X after tsx *yp
*xp
length SP after pushm x, d
X + OFST
X
X at rts D SP after function call
CCR
PC SP before function call
*xdata
*ydata
Figure 6-4: Stack Contents During Function Operation
After the closing brace of the function in the above listing, two
important operations take place. First, the contents contained in the
X register on entry to the function are restored by the instruction
ldx 6,x
and the stack pointer content is restored to the value it contained
when the function was entered. At this point in the program, an rts
instruction will return the program control to the instruction follow
ing the jsr or bsr instruction used to enter the function code
originally.
When the function return is executed, the registers D, E, Y, Z, and
CCR are all undefined. A 16-bit return from the function will be returned
in the D register, and a 32-bit return will be contained in the E and the D
register. The least significant portion of the return is in the D register.