Page 192 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 192
6.4 Calling And Returning Mechanisms 169
* original variables
RESULT; DS.W 1
*
* SUBROUTINE DOTPRD
* LOCAL VARIABLES
*
TERM: EQU 0
MBYTES: EQU 2
* Saved registers
*
REGCC: EQU 0+NBYTES ; saved condition code register
REGB: EQU 1+NBYTES ; saved accumulator B ~ note "backwards"
REGA: EQU 2+NBYTES ; saved accumulator A — note "backwards"
REGX: EQU 3+NBYTES ; saved index register X
REGY: EQU 5+NBYTES ; saved index register Y
*
DOTPRD: LEAS -NBYTES,SP
LDAA REGA,SP
LDAB REGB,SP
MUL
STD TERM, SP ; First term to local variables
LDAA REGX+l r SP
LDAB REGY+1,SP
MUL
ADDD TERM, SP ; Dot product into D
STAA REGA, SP ; Dot product high byte to output parameter
STAB REGB, SP ; Dot product low byte to output parameter
LEAS NBYTES, SP ; Deallocate local variables
RTI
Figure 6.43. An SWI Handler
entry: MOVW #DOTPRD,$FFP6
a. Initialization (done just once)
LDAA #1
LDAB #2
LDX #3
LDY #4
SWI
STD RESULT ; Put in global location
BRA *
b. Calling sequence (done each time the operation is to be performed).
Figure 6.44. Calling an SWI Handler