Page 215 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 215
192 Chapter? Arithmetic Operations
the values of the operands are pushed on the stack before the subroutine call with only
the result on top of the stack after the return. (See Figure 7.10, and notice particularly
that the subroutine for an operation with two operands leaves only the result on top of
the stack.) To place these parameters on the stack, we will here assume that a macro
PUSH has been written that pushes the 4-byte number at address ADDR onto the stack,
low byte first, with PUSH ADDR. Similarly, we will assume that a macro PULL has
been written so that
PULL ADDR
will pull a 4-byte number off the stack, high byte first, and place it at the address ADDR,
Variables x, y, u, w, and z are at addresses X, Y, U, W, and Z, respectively, and the
constant 2 is at address K2. This can be implemented with the directives in (9). We can
evaluate (8) with the program segment (10) , where the symbolic names of the variables
are in (9). In this segment, FPMUL, FPADD, and FPDIV are subroutines to multiply,
add, and divide floating-point numbers, while SIN is a subroutine to calculate the sine of
a floating-point number. The movement of the stack is shown after each operation in
Figure 7.11.
X: DS.L 1
Y: DS.L 1
U: DS.L 1 (9)
W: DS.L 1
Z: DS.L 1
K2: DS.L 1
b. Two Operand Operations
Figure 7.10. Passing Parameters on the Stack