Page 104 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 104
3,7 Summary HI
3.7 Summary
In this chapter we looked at the addressing modes in the 6812. We saw four general
themes: the use of page zero, the use of index registers, the use of relative addressing for
position independence, and the use of stack addressing for reentrancy and recursion.
With the first theme, we saw inherent and page zero addressing are useful for
improving static and dynamic efficiency over direct addressing. Put the most commonly
accessed variables in registers, using inherent addressing to access them, and put the next
most common variables in page zero, using page zero addressing to access them.
For the second theme, we saw that index registers may be used efficiently to handle
addresses that require several accesses and that index registers may be useful for data
structure accesses. Index addressing is the fastest and shortest index addressing option and
index addressing using 5-bit offsets is available for locations close to that pointed to by
the register, while 16-bit offsets are available for all accesses. We also saw that the
accumulators may be used, in lieu of an offset, to combine a variable in an index register
with a variable in an accumulator to get the effective address. Index registers and their
addressing modes provide a lot of power, which we explore further throughout this book.
With the third theme, the program counter is used as a kind of index register and the
same steps used to carry out index addressing are used to carry out relative addressing
using the program counter in place of an index register. Although the mechanics are the
same, the effect is quite different, and the representation of the address is different. In
particular, the address in the instruction using relative addressing is the effective address,
not an offset, while the machine code for the instruction uses a relative offset, which is
the amount that must be added to the program counter to get the effective address. This
mode is useful in making programs position independent, so that they may be mass
produced in ROMs and many different systems can use the same ROM.
The last theme showed how the stack pointer can be used with an offset to access
local variables and parameters passed on the stack. The reentrancy and recursion
techniques are shown to be easily implemented using stack pointer addressing.
This chapter covered the rich collection of addressing modes in the 6812. These
correspond to the modes in most of the other microcomputers and to most of the useful
modes in any computer. Now that you know them, you should be prepared to use them
with any instruction in the 6812 (where they are permitted) as we discuss these
instructions in the next chapter. You should know which mode to use, based on our
study of the themes above so that you can produce shorter, faster, and clearer programs.
Do You Know These Terms?
See the end of Chapter 1 for instructions.
addressing pointer register independent reentrant
addressing modes index register program counter subroutine
accessed index addressing relative nested allocation
inherent post byte relative unsigned overflow
implied offset relative offset signed overflow
self-modifying autoincrement sixteen V inner product
code autodecrement complement three-address
page zero indirect addressing recursive instruction
mode position subroutine jump vector