Motorola HC12 Refrence Manual page 382

Table of Contents

Advertisement

C.2.1 Register Pushes and Pulls
The M68HC11 has push and pull instructions for A, B, X, and Y, but requires separate
8-bit pushes and pulls of accumulators A and B to stack or unstack the 16-bit D accu-
mulator (the concatenated combination of A:B). The PSHD and PULD instructions al-
low directly stacking the D accumulator in the expected 16-bit order.
Adding PSHC and PULC improved orthogonality by completing the set of stacking in-
structions so that any of the CPU registers can be pushed or pulled. These instructions
are also useful for preserving the CCR value during a function call subroutine.
C.2.2 Allocating and Deallocating Stack Space
The LEAS instruction can be used to allocate or deallocate space on the stack for tem-
porary variables:
LEAS
LEAS
The (de)allocation can even be combined with a register push or pull as in the following
example:
LDX
X is loaded with the 16-bit integer value at the top of the stack, and the stack pointer
is adjusted up by eight to deallocate space for eight bytes worth of temporary storage.
Post-increment indexed addressing is used in this example, but all four combinations
of pre/post increment/decrement are available (offsets from –8 to +8 inclusive, from X,
Y, or SP). This form of indexing can often be used to get an index (or stack pointer)
adjustment for free during an indexed operation (the instruction requires no more code
space or cycles than a zero-offset indexed instruction).
C.2.3 Frame Pointer
In the C language, it is common to have a frame pointer in addition to the CPU stack
pointer. The frame is an area of memory within the system stack which is used for pa-
rameters and local storage of variables used within a function subroutine. The follow-
ing is a description of how a frame pointer can be set up and used.
First, parameters (typically values in CPU registers) are pushed onto the system stack
prior to using a JSR or CALL to get to the function subroutine. At the beginning of the
called subroutine, the frame pointer of the calling program is pushed onto the stack.
Typically, an index register, such as X, is used as the frame pointer, so a PSHX in-
struction would save the frame pointer from the calling program.
Next, the called subroutine establishes a new frame pointer by executing a TFR S,X.
Space is allocated for local variables by executing an LEAS –n,S, where n is the num-
ber of bytes needed for local variables.
MOTOROLA
C-2
–10,S
10,S
8,S+
HIGH-LEVEL LANGUAGE SUPPORT
;Allocate space for 5 16-bit integers
;Deallocate space for 5 16-bit ints
;Load return value and deallocate
CPU12
REFERENCE MANUAL

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cpu12

Table of Contents