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

PROBLEMS                                                            219


        2 2 . Write a subroutine FPIN to convert a decimal floating-point number input on the
        keyboard in "scientific notation," which is a positive integer less than 100,000, to a
        single-precision binary floating-point number pushed on the top of the stack. Assume
        you have a subroutine FPADD and FPMUL. Follow the steps in Figure 7.5.

        2 3. Give an example that shows that the round bit r can not be eliminated, that is, give
        an example that shows that it really is not superfluous.

        24. Give an example of the addition of two floating-point numbers, each with a
        magnitude less than or equal to 1, that results in the biggest possible rounding error.
        Repeat the problem for multiplication.

        2 5. Write a subroutine FPDIV to divide a single precision floating-point number on
        the top of the stack into the second number on the stack, popping both numbers and
        pushing the remainder on the top of the stack.

        2 6. Write a subroutine FPADD to add a single precision floating-point number on the
        top of the stack into the second number on the stack, popping both numbers and pushing
        the result on the top of the stack.

        27. Write a program to make your microcomputer a simple four-function calculator,
        using subroutines from Hiware's library, subroutine FPDIV of problem 7.24, and input
        and output subroutines FPIN and FPOUT of problems 20 and 21. Your calculator should
        use Polish notation and should only evaluate +, —, ~, and /, inputting data in the form of
        up to eight decimal digits and decimal point (e.g., 123.45,1234567.8,12., and so forth).

        28. Write, in DC.B's, the parameters pointed to by X when the MEM instruction is
        executed for each of the linguistic variables in Figure 7.20, for the data in Figure 7.23.
        The highest C is 50, the lowest B is 40, the highest B is 70, and the lowest A is 60.

        29. Assume a function f(x) is graphed as the grade B graph in Figure 7.22. Write a
        shortest assembly language subroutine F and a table T stored using a DC.B directive, to
        evaluate f(x) where 40 s x s 70 is input in accumulator A, which leaves the result in
        accumulator A. [Hint: see Figure 9.12 in the CPU12 manual (CPU12RG/D)].
   237   238   239   240   241   242   243   244   245   246   247