Page 378 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 378
12.2 The 6808 355
or unsigned 8-bit offset index addressing using the index register HX, the stack pointer
SP, or HX without an offset. DBNZA and DBNZX are similar to the 6812 DBNE using
accumulator A, but DBNZ using a stack-indexed address is especially suited to using a C
local variable for a loop counter. For instance, the following program clears a 16-byte
vector whose base address is initially in HX; although the accumulator can be better used
as a loop count, using a local variable shows this special 6808 mechanism:
LDAA #$10 ; generate loop count
PS HA ; save it on the stack
LOOP: CLR , X ; clear word pointed to by HX (no offset)
AIX # 1 ; i ncrement pointer
DBNZ 0, SP, LOOP ; count down
PULA ; restore the stack
The branch instructions have a means to test the half-carry condition code bit H,
which are BCHS and BHCC; a means to test the interrupt request pin IRQ, which are BIH
and BIL; and the interrupt request mask, which are BMC and BMS. Finally, the BSET,
BCLR, BRSET, and BRCLR instructions use a binary bit number to indicate which bit is
set, cleared, or tested, rather than the bit mask used in the 6811 and 6812. For instance,
the instruction BSET 3 , $ 10 will set bit 3 in word $10.
* SUBROUTINE DOTPRD
* LOCAL VARIABLES
TERM: EQU 1 ; Note: location 0,SP is first free byte above stack
NBYTES: EQU 2
* PARAMETERS
RADDR: EQU 3 ; Return address
LOCV: EQU 5 ; Vector V passed by value
LOCW: EQU 7 ; Vector W passed by value
DOTPRD: AIS #-NBYTES ; Allocation for local variables
LDAA LOCV,SP ; Get V(0)
LDX LOCW,SP ;GetW(0)
MUL
S T X TERM, SP ; High byte to local variable
STAA TERM+1, SP ; Low byte to local variable
LDAA LOCV+1,SP ; Get V(l)
LDX LOCW+1,SP ;GetW(l)
MUL
ADD TERM+1, SP ; Add low byte
STAA TERM+1, SP ; Store low byte
T X A ; Get high byte
ADC TERM,SP ; Add high byte
TAX ; Put high byte in X
LDAA TERM+1, SP ; Get low byte
AIS #NBYTES ; Deallocate local variables
RTS
Figure 12.4. A 6808 Dot Product Subroutine

