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

PROBLEMS                                                             175

           PSHA
           PSHB
           PSHX
           CLR      I, -SP                  Hole for NUM
           BSR     SEARCH
           PULA                             Put NUM into A
           LEAS    4, SP                    Balance stack
                             Figure 6.47. Program for Problem 13

        14. Write a position-independent reentrant subroutine QUAD that evaluates the quadratic
                  2
        function ax  + bx + c, where signed 16-bit arguments a, b, c, and x are passed on the
        stack, named PARA, PARE, PARC, and PARK, and the output is passed on the stack,
        named RESULT. In order to demonstrate local variables, as part of your subroutine, store
          2
        ax  in a 16-bit local variable on the stack. Write a calling sequence that pushes 1, 2, 3,
        and 4; calls QUAD; pulls the result from the stack; and stores the result in global variable
        ANSWER.

        15. Write a shortest position-independent reentrant subroutine PAR that computes the
        parallel resistance of two resistors Rl and R2, where unsigned 16-bit arguments are
        passed on the stack and named Rl and R2, and the output is passed on the stack, named
        RESULT. In order to demonstrate local variables, as part of your subroutine, store Rl
        times R2 in a 32-bit local variable on the stack. Write a calling sequence that pushes 100
        twice, calls PAR, pulls the result from the stack, and stores the result in global variable
        ANSWER.

        16. Do the same thing as in Problem 13, assuming that the input parameters are passed
        after the call in the same order, while the parameter NUM is returned on the stack as
        before. Do not use a BRA instruction before the parameter list, but follow the style of
        Figure 6.27. Provide an example of a calling sequence.

        17. Write a position-independent reentrant subroutine QUAD that evaluates the quadratic
                  2
        function ax  + bx + c, where signed 16-bit arguments a, b, c, and x are passed after the
        call, named PARA, PARB, PARC, and PARX, and the output is passed after the call,
        named RESULT. In order to demonstrate local variables, as part of your subroutine, store
          2
        ax  in a 16-bit local variable on the stack. Do not use a BRA instruction before the
        parameter list but follow the style of Figures 6.25 and 6.26. Write a calling sequence
        that writes 1, 2, 3, and 4 into PARA, PARB, PARC, and PARX; calls QUAD; and moves
        the result to global variable ANSWER.

        18. Write a shortest position-independent reentrant subroutine PAR that computes the
        parallel resistance of two resistors, where unsigned 16-bit arguments are passed after the
        call and named Rl and R2 and the output is passed after the call, named RESULT. In
        order to demonstrate local variables, as part of your subroutine, store Rl times R2 in a
        32-bit local variable on the stack. Do not use a BRA instruction before the parameter list,
        but follow the style of Figures 6.25 and 6.26. Write a calling sequence that writes 100
        into Rl and R2, calls PAR, and moves the result to global variable ANSWER.
   193   194   195   196   197   198   199   200   201   202   203