Page 373 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 373
350 Chapter 12 Other Microcontrollers
* SUBROUTINE DOTPRD
* LOCAL VARIABLES
TERM: EQU 0
* PARAMETERS
RADDR: EQU 2
LOCV: EQU 4
LOCWi EQU 6
DOTPRD: PSHX ; Allocate locals
TSX ; SP+1 -> X (Note: SP -> first free byte)
LDAA LOCV,X
LDAB LOCW,X
MUL
STD TERM, X ; Copy first term to local variables
LDAA LOCV+1,X
LDAB LOCW+1,X
MUL
ADDD TERM,X ; Dot product into D
P U L X ; Deallocate local variables
RTS
Figure 12.1. A 6811 Dot Product Subroutine
6811 lacks some of the instructions and many of the addressing modes of the 6812 (see
Table 12.1). You will be concerned mostly with the absence of stack index addressing.
Before we examine the differences, we should emphasize the similarities. The
instruction sets are so similar that many of the programs in earlier chapters can be used
in the 6811. The example that follows, the subroutine DOTPRD of Chapter 6 with the
parameters passed on the stack, shows how similar the 6811 is to the 6812.
In Figure 12.1, bold type shows differences from the 6812 example, which are in
allocating and indexing the stack. The 6811 has immediate, page-zero, 16-bit direct, and
inherent addressing, exactly as in the 6812. The relative address mode is available only as
an 8-bit relative address in BRA type of instructions, which behave exactly like their
counterparts in the 6812. Indirect, postincrement, predecrement, and program counter
relative addressing modes are missing in LDAA and similar instructions, and the index
mode is only available in the form where an unsigned 8-bit offset in the instruction is
added to the 16-bit index register X or Y. This program had to use the X register to
access the local variables and parameters on the stack because there is no indexing mode
that uses the stack pointer SP. The stack pointer actually points to the first free byte
below the top of the stack; the TSX instruction puts SP+1 in X, so the top of the stack
is at O^C. The LEAS instruction is absent from the 6811, so we allocate using PSHX, or
DBS, or temporarily putting SP into accumulator D and using SUED; and we deallocate
using PULX, or INS, or temporarily putting SP into accumulator D and using ADDD.
Also, instructions that read, modify, and write the same word in memory, such as INC
COUNT, may use only 16-bit direct or 8-bit unsigned offset indexed addressing. All 6811
address arithmetic is unsigned, so that if X contains $1000, then LDAA $FF, X loads
accumulator A from locations $1000 to $10FF. Programs using the 16-bit index
addressing mode of the 6812, such as LDAA $1000, X have to be modified too,

