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

PROBLEMS                                                            109


                                       PROBLEMS

         1. Suppose that the ORG statement is removed from the assembler. How can such
         statements be handled by other directives, and what assumptions have to be made to
         make it possible to completely replace the ORG statement?

         2 . Although the assembler has an ALIGN, an EVEN, and a LONGEVEN assembler
         directive, the ORG directive can align the location counter to an integer multiple of a
         constant. Write such an ORG directive that aligns the next location to the next multiple
        of four. Do not move the location counter if it is already aligned (low two bits are zero).


         3 . An I/O port at location $cb is to be loaded with a constant. If bit 2 is asserted,
         input hardware is activated; if bit 3 is asserted, output hardware is activated; if bit 5 is
         asserted, input hardware can cause an interrupt; and if bit 7 is asserted, output hardware
         can cause an interrupt. Write EQU directives that define four constants that can be ORed
        together to generate a constant to be stored into the memory location or can be used with
         BSET, BCLR, BRSET or BRCLR instructions. The constant ION turns on the input,
         OON truns on the output, I INT enables input interrupts, and OINT enables output
         interrupts. Write a MOVE instruction that turns on the input and output hardware and
         enables input interrupts. Write an instruction that subsequently enables output interrupts
         and another that disables output interrupts, neither of which change any other bits in
         location $cb except bit 7. Comment on the use of symbols to improve clarity.

        4 . A two-dimensional array of 8-bit elements is to have R rows and C columns. Write
        EQU statements to define R to 3 and C to 4. Write a DC. B statement to allocate enough
        storage for the array for any R and C. Write a shortest program segment that reads the
        byte at row i column j into accumulator B, assuming rows and columns are numbered
         starting with zero, and elements of a row are stored in consecutive memory locations.

        5 . A vector of four 16-bit constants is to be initialized after location RATES, each of
        which are calculated as 8,000,000 divided by 16 times the desired rate. For example, to
        get a rate of 9600, put 52 into the element. The first element is to have a rate of 9600;
        the next, of 1200; the next, of 300; and the last of 110. Write this DC directive.

        6 . A vector of eight 8-bit constants is to be initialized after location PTRNA, each of
        which is a bit pattern displayed on consecutive lines on a screen to draw a letter A. For
         instance, the top row of eight bits will be $10, the next row will be $28, and so on.
        Write this DC directive.

        7 . Write a directive to clear all bytes from the current location counter to the location
        whose four low address bits are zero.

        8 . Write a directive to fill all bytes from the current location counter to location
        $FFF6 with value $FF.
   127   128   129   130   131   132   133   134   135   136   137