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

PROBLEMS                                                            217


                                      PROBLEMS



        1 . How would you rewrite the subroutines of Figures 7.1 and 7.2 if you did not want
        any registers changed by the subroutines except D, the output parameter?

        2 . Write a shortest subroutine DIVS that divides the signed contents of B by the
        signed contents of A, putting the quotient in B and the remainder in A.
        3 . Rewrite the subroutine of Figure 7.4 so that, using INCH, the digits can be input
        from the terminal as a string. A carriage return should terminate the input string so that
        zero through five digits can be put in. (The empty sequence should be treated as zero.)
        Your subroutine should do the same thing as the one in Figure 7.4 as long as the
        number of digits put in is five or less. INCH inputs a character from the keyboard,
        returning it in A.

        4 . Rewrite the subroutine of Figure 7.7 so that (DUTCH can be used to output the
        decimal digits to the terminal. OUTCH prints the character input in A.


        5 . Write a shortest subroutine INBCD using INCH that will input six ASCII decimal
        digits and place the equivalent 6-digit BCD number at the address passed in X. INCH
        inputs a character from the keyboard, returning it in A.


        6 . Write a shortest subroutine OUTBCD that will output the 6-digit BCD number
        pointed to by X to the terminal. The subroutine, using OUTCH, should display the
        equivalent 6-digit decimal with leading zeros suppressed. OUTCH prints the character in
        A.

        7 .  Using the subroutine OUTCH, write another shortest subroutine OUTBCD A that
        puts out the BCD contents of accumulator A to the terminal. OUTCH prints the
        character in A.

        8 . Write a shortest subroutine that will replace the DAA instruction when two base-
        13 digits are stored per byte.


        9.   Give a sequence of subroutine calls for the following formula.
             z = sqrt((17 + (x/y)) * (w - (2 + w/y)))


        Provide a graphical parsing tree for this formula, and show assembly language statements
        (dc.b directives, etc.) for the storage of the parsing tree for z so that Problem 7.10 can be
        done.

        10. Write a flow chart that will read the data structure of Problem 7.9 (or any similar
        formula tree stored in a linked list structure), and then write an assembly language source
        program (in ASCII) for the subroutine calls needed to evaluate the formula.
   235   236   237   238   239   240   241   242   243   244   245