Page 93 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 93

70                                             Chapter 3 Addressing Modes


        For example,
                                     LDAA <L,PCR

        can load any word into A that can be reached by adding an 8-bit signed number to the
        program counter. (Recall that the PC is pointing to the next instruction just below the
        LDAA instruction when the effective address L is calculated.) The instruction
                                     LDAA >L,PCR
        can be used to access words that are farther away than -128 to + 127 locations from the
        address of the next instruction; it adds a 16-bit offset to the current value of the program
        counter to get the effective address. Although the machine coding of relative addressed
        instructions is the same as that of index addressed instructions, do not dwell too much on
        that similarity because the offset put in the machine code is determined differently.
            Program counter relative indirect addressing can be used to access locations such as
        I/O ports as in
                                     LDAA [L,PCR]
        Assuming that L is 18 bytes below this instruction, the machine code is given by










        where $A6 is the opcode byte for any LDAA index mode; the post byte $FB indicates
        indirect index addressing with 16-bit offset, but using the program counter as the "index
        register", and the last two bytes are added to the program counter. The indirect address
        ($12 in the example above) is in a location relative to the program. If the program is
        loaded into a different location, the offset $12 is still used to get the indirect address.
        Such use of relative and indirect relative addressing lets the program have one location
        and only one location where a value is stored, so that a downloaded file can insert the
        value in one place to run the program anywhere it is stored.
            Branch and long branch instructions do not need the ",PCR" symbol in the
        instruction because they only use relative addressing with 16-bit relative offsets.
        However, the BSR L, having an 8-bit offset, doesn't have a corresponding long branch
        to subroutine. But JSR L,PCR is a 16-bit position independent subroutine call that
        has the same effect as the missing LBSR L.
            A 16-bit position independent indirect subroutine call, JSR [ L, PCR ], can jump
        to a subroutine whose address is in a "jump table," as discussed in a problem at the end
        of this chapter. Such jump tables make it possible to write parts of a long program in
        pieces called sections and compile and write each section in EEPROM at different times.
        Jumps to subroutine in a different section can be made to go through a jump table rather
        than going directly to the subroutine. Then when a section is rewritten and its
        subroutines appear in different places, only that section's jump table needs to be
        rewritten, not all the code that jumps to subroutines in that section. The jump table can
        be in EEPROM at the beginning of the section, or in RAM, to be loaded at run time.
   88   89   90   91   92   93   94   95   96   97   98