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

312                                   Chapter 10 Elementary Data Structures

                   MOVE     BIT, 1, -SP      ; Bit to be written
                   MOVB     INDEX, 1, -SP    ; Index to be written
                   BSR      STRBIT
                   LEAS     2, SP            ; Balance stack

         6 . Assume S[100] stores a 100-character (maximum) string that is accessed by an 8-
         bit index I that is initialized to zero. Write a shortest subroutine READ to return in
         accumulator A the elements one at a time, beginning with element zero.

         7 , Write a subroutine DISPLY, using DUTCH, whose input is in A, that will display
         a zero-origin vector with the structure of Problems 4 and 5 8 rows by 32 columns of O's
         and 1's. The bits of the vector must be displayed left to right, 32 consecutive bits per
         row. You may assume that the address of the vector is passed after the call with the
         sequence
                           BSR     DISPLY
                           DC.W    VECTOR
         8 . Give two subroutines PSHBT and PLBT, to go with those of Figure 10.7, that
         will push and pull the contents of accumulator B on the bottom of the deque.
        9 , One would not usually tie up two index registers and an accumulator to implement
         a deque. Rewrite the two subroutines in Figure 10.7 and the initialization sequence to
        push and pull bytes from B and the top of the deque when the deque is stored in memory
         as
                         COUNT:    DS. B     1      ; Deque count
                         TPOINT: DS.W        1      ; Top pointer
                         BPOINT: DS.W        1      ; Bottom pointer
                         DEQUE:    DS.B      50     ; Buffer for the deque

         Here, COUNT contains the number of elements in the deque, and TPOINT and BPOINT
        contain, respectively, the addresses of the top and bottom of the deque. The subroutines
         should not change any registers except B, which is changed only by the pull subroutine,

         10. Assuming that the location of the deque and the error sequence are fixed in memory,
         how would you change the subroutines of Figure 10.7 so that the machine code generated
        is independent of the position of the subroutines? How would you change these
         subroutines if the size of the deque was increased to 400 bytes?
         11. Do you see how you can avoid keeping a counter for the deque? For example, can
        you check for an empty or full deque without a counter? "Full" means the last element
        is now used up.

         12. Assume that a 10-byte shift register is established in your program with

                         SHIFTR: DS          10       ; Buffer memory
                         POINT:    DS        2        ; Pointer to SHIFTR

        Write a subroutine SHIFT to put a byte into the shift register from B and pull a byte out
        into A.
   330   331   332   333   334   335   336   337   338   339   340