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

80                                             Chapter 3 Addressing Modes

        it is not clear whether the load is executed before the + or after the +. Note that if the
        latter is true, the + would have no effect on the instruction. Indeed, in the 6812, the + is
        carried out before the operation; in this case a load, so that
                                      LDX 2,X+
         is the same as
                                      LDX 2,X-

            For any load instruction involving the same index register for the location of the
        operand and the location of the result, the general rule is that postincrementing has no
        effect on the instruction. However, the fact that the postincrementing is carried out before
        the operation produces an unexpected result in the store counterpart of the load
        instruction just discussed. For example, with

                                      STX 2,X+
        suppose that X initially contains 373. After the instruction is executed, one will find that
        X becomes 375, and 375 has been stored in locations 373 and 374. We conclude this
        discussion by noting that predecrementing has none of these ambiguities. For example,
        if X initially contains 373 before the instruction
                                      STX 2,-X

        is executed, then 371 will be stored in locations 371 and 372.
             There is often considerable confusion about LDX (direct), LDX #, and LEAX.
        Consider the following examples, assuming location $820 stores $1234.

                                      LDX $820
        will load $1234 into X. Direct addressing loads the data located at the instruction's
         address. However, immediate addressing loads part of the instruction into the register, as

                                      LDX #$820
        will load $820 into X. Sometimes, immediate addressing is used to load an address into
        memory so that pointer addressing (index addressing with zero offset) can access the data:
                                      LDX #$820
                                      LDX 0,X
         will eventually load $1234 into X. Also, the LEAX instruction loads the effective address
        into an index register. When it is used with program counter relative addressing, it has
        the same effect as LDX # but is position independent.

                                      LEAX $820,PCR
                                      LDX 0,X

        will eventually load $1234 into X. But LEAX can be used with other addressing modes
        for other effects; for instance LEAX 5, X adds 5 to X, and LEAX D, X adds D to X.
   98   99   100   101   102   103   104   105   106   107   108