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

PROBLEMS                                                             311


                                     PROBLEMS

        1. What are the limitations on the precision and length of the vector Z that are
        accessed by program segments (2) and (3)? How would you change these segments for a
        vector Z with length 500?

        2 . Write a shortest subroutine READY that returns in index register Y (high 16 bits)
        and accumulators A and B (low 8 bits), the ith element of a zero-origin vector. For
        instance, V may be allocated as in V DS M*N, where V has precision M bytes (M & 4)
        and cardinality N elements. To read V, the parameters can be passed on the stack with the
        calling sequence shown below. If M is 1, pass the result in ACCB; if 2, pass it in
        ACCI>, if 3, pass it in Y (msb) and ACCB (Isb); and if 4, pass it in Y (msb) and ACCD
        (Isb).

                                   MOW              #V,2,-SP
                                   MOVE             #M rl,-SP
                                   MOVB             #i,l,-SP
                                   JSR               READV
                                   LEAS              4,SP

        3 . Write a shortest subroutine WRITEV that writes the M bytes (M s 4) into the ith
        element of a one-origin vector. For instance, the data may be in index register Y (high 16
        bits) and accumulators A and B (low 8 bits). V may be allocated as in V DS M*N r
        where V has precision M bytes (M s 4) and cardinality N elements. To write the data into
        V, the parameters can be passed on the stack with the calling sequence as shown below.
        Pass returned results as in Problem 2.

                       MOVW        #V, 2, - SP ; Vector base address
                       MOVB        #M, I  f -SP ; Vector precision
                       MOVB        #i, 1, -SP ; Desired element number
                       JSR         WRITEV     ;
                       LEAS        4, SP      ; Balance stack

        4 . Consider the zero-origin vector of 32 bytes in locations 0 through 31. Assume that
        the bits in this vector are labeled 0 to 255 beginning with the first byte in the vector and
        going right to left within each particular byte. Write a subroutine SETBIT that will set
        the ith bit in this vector assuming that the value of i is passed on the stack with the
        calling sequence

                  MOVB     #5 8,1, - SP     ; Value of i into parameter
                  BSR      SETBIT
                  LEAS     1, SP            ; Balance stack

        5 .       Write a subroutine STRBIT that will store the binary-valued variable BIT
        in me ith bit of the zero-origin vector in Problem 4. The value of BIT and INDEX can
        be passed on the stack with the calling sequence
   329   330   331   332   333   334   335   336   337   338   339