Page 88 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 88
3.2 Post Byte Index Addressing Modes 65
8, a comma, and the register name with a "+" or "-" symbol. If "+" appears, the index
register is incremented by the delta value, and if "-" appears, the index register is
decremented by the delta value; if this symbol appears before the register name,
incrementing or decrementing is done before effective address calculation, and if the
symbol appears after the register, incrementing or decrementing is done after the
calculation. Consider an example of postincrementing by 1; if X had $843,
LDAA 1,X+
loads the contents from location $843 into A and then increments the contents of X by I
to make it $844. For an example of preincrementing by 1, if X had the value $843,
LDAA 1,+X
increments the contents of X by 1, and then loads the contents from location $844 into
A. An example of postincrementing by 2, if X had the value $843,
LDD 2,X+
loads the contents from locations $843 and $844 into D and then increments the contents
of X by 2 to make it $845. For an example of predecrementing, if X had the value $843,
LDAA 1,-X
decrements the contents of X by 1 to make it $842 and then loads the contents from
location $842 into A. Delta can be as high as 8.
These addressing modes are encoded in the post byte as follows (see Figure 3.2):
Bits 7 and 6 identify the register (00 is X, 01 is Y, and 10 is SP, but 11 is not used for
this mode), bit 5 is 1, bit 4 is 0 if the index value changes before address calculation and
1 if after, bit 3 is 1 if decrementing and 0 if incrementing. For incrementing, bits 2 to 0
are the value of delta minus 1 (or equivalently, delta is the low-order three bits plus 1).
For decrementing, bits 2 to 0 are the value of delta, as a negative two's-complement
number, to be added to the index register. For example, for LDAA 1, X+ the post byte
is $30, for LDAA 1,+X the post byte is $20, for LDD 2 ,X+ the post byte is $31, for
LDAA 1, -X it is $2F, and for LDAA 2, -X it is $2E, and so on.
Figure 3.5 illustrates how the delta value fetched from memory can be added to the
index register. The index value before or after modification can be used as the effective
address by appropriately setting the switch that determines the effective address.
Consider addition again. If you want to add the word at location $843 with the word
at location $844, putting the result at location $845, execute the code in Figure 3.6.
Figure 3.6. Program Segment to Add Two Bytes Using Autoincrementing