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

PROBLEMS                                                              83


        to by X, toward less significant bits in that byte, and then toward bytes at consecutively
        higher addresses. If accumulator A is a bit number n, this program segment sets bit n in
        the bit vector pointed to by X.

        9 . Write a shortest program segment, which is to be executed only once, that adds a
        24-bit number at locations $811 to $813, to a 24-bit number at $814 to $816 to get a
        24-bit result at $817 to $819 but that does not use any index registers; it uses only self-
        modifying code. Each address's low byte is decremented after each time it is used,

         10. Write a shortest program segment that adds a 24-bit number to a 24-bit number to
        get a 24-bit result but that does not use any index register, only indirect addressing. Use
        locations $811 and $812 to hold the pointer to the first 3-byte number (which is the
        address of its least significant byte), locations $813 and $814 to hold the pointer to the
        second number (which is the address of its least significant byte), locations $815 and
        $816 to hold the pointer to the result (which is the address of its least significant byte).
        Assume that no byte of any of the 24-bit numbers spans a page discontinuity, where the
        low byte of the address is zero. This program segment need be executed only once.

         11. Suppose that Y = 613 and X = 918 before each of the following instructions is
        executed. Give the contents of the registers X and Y after each is executed, in decimal.
        Then explain what is stored where if STY 2 , -Y is executed with Y = 613.
              (a) LEAK 2 , -Y           (b) LEAX 2 , -X         (c) LEAX 2 , Y+

         12. Give the shortest 6812 instruction sequences that carry out the same operation as
        the following nonexistent 6812 instructions. Condition codes need not be correctly set.
              (a)AAX                       (b)ADX                    (c) LSLX

        13. A section is a collection of n subroutines that are assembled together and written
        together in a PROM, EPROM, or EEPROM. The first 2 n bytes of storage for each
        section contain the direct address of each subroutine in the section, in a jump vector.
        The first two bytes are the address of the first subroutine, and so on. Suppose section 1
        begins at $FOOO, so subroutine 3's address would be in $f006. In another section, a call
        to subroutine m in section 1, puts the 16-bit number from location 2 m + $fOOQ into
        the program counter. Show the machine code for parts (a) and (b).
             (a) Write a single instruction, at location $d402, to call subroutine 3.
             (b) How do we fill the "jump table" at location $fOOO with addresses of subroutines
        at run time (assuming the jump table is in RAM). In particular, if the subroutine at
        location f is a label at the beginning of the third subroutine whose address is at location
        $f006, write a program sequence to generate and write this address in the vector.
             (c) How does this capability simplify the debugging of large programs?

        14. The jump vector of problem 13 is to be made position independent. Each element
        is a relative offset to the subroutine. Repeat part (a), (b), and (c) of problem 15 for this
        jump vector. Write parts (a) and (b) as a program segment, where X points to the jump
        table's beginning.
   101   102   103   104   105   106   107   108   109   110   111