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

218                                         Chapter 7 Arithmetic Operations


        11. Give the graphical parsing trees needed to efficiently evaluate the formula
                    2
                         2
                                                     2
                                    2
             2 = (4x  + y ) + (y/2x)  ln(Vx + (4x + y)  + Hy)
        Assume that you have subroutines to evaluate a square root and a natural logarithm. To
                                                                              2
        do an efficient calculation, you should evaluate the common subexpression (e.g., x )
        first.
        12. Show how the formulas
             delta = delta + c                  s = s + (delta * delta)
        can be more efficiently evaluated by passing arguments through registers instead of on
        the stack as was done in the text.
        13. Modify the subroutine of Figure 7.14 so that the Z flag is returned correctly for a
        4-byte negate.

        14. Write a shortest subroutine that multiplies the 24-bit unsigned number in A (high
        byte) and X with the 24-bit unsigned number in B (high byte) and Y, returning the
        product in X (most-significant 16 bits), Y (middle-significant 16 bits), and D (least-
        significant 16 bits) .

        15. Write a shortest subroutine that multiplies the 24-bit signed number in A (high
        byte) and X with the 24-bit signed number in B (high byte) and Y, returning the product
        in X (most-significant 16 bits), Y (middle-significant 16 bits), and D (least-significant
         16 bits) .

        16. Write a shortest subroutine DIVS that divides the signed contents of Y and D by
        the signed contents of the next word on the stack, putting the quotient in Y and D.

        17. Write a shortest subroutine DIVS that divides the signed contents of Y and D by
        the signed contents of the next word on the stack, putting the remainder in Y and D.

        18. Because the half-carry is not set correctly by the instructions SUBA and SBC A,
        how do you subtract multiple byte BCD numbers? Explain.
        19. Write a subroutine to convert a decimal fraction .xyz . . . input from the terminal
        using INCH, to the closest 16-bit binary fraction returned in D. The decimal fraction can
        have up to five decimal digits terminated by a carriage return.
        2 0. Write a subroutine to convert a 16-bit binary fraction in D to a decimal fraction
        .xyz . . . and output it from the terminal using OUTCH. The decimal fraction can have
        up to five decimal digits terminated by a carriage return.

        21. Write a subroutine FPOUT to convert a single-precision binary floating-point
        number, which is a positive integer less than 100,000, popped from the top of the stack
        to a decimal floating-point number that is displayed on a terminal screen. Assume you
        have FPADD and FPMUL, and follow the steps in Figure 7.6.
   236   237   238   239   240   241   242   243   244   245   246