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

176                                Chapter 6 Assembly Language Subroutines


        19. One reason for not passing output parameters after the call is that a subroutine that
        calls another subroutine and has some parameters passed back to it after the call will not
        always be reentrant. Explain why this is so. Are there similar restrictions on input
        parameters?

        2 0. Give an example of passing output parameters after the call where the program can
        still be stored in ROM.

        21. Write a subroutine to search an N-byte vector Z until a byte is found that has the
        same bits in positions 0,3,5, and 7 as the word MATCH. The address of Z is passed as
        the first entry AZ in a table, the value of MATCH is passed below it in the table, the
        value of N is passed below it in the table, and the address of the first byte found, ADDR,
        is passed below it in a table. If no byte is found in Z with a match, $FFFF should be
        placed in AZ. The address of the table is in X when the subroutine is called.

        2 2, Write a position-independent reentrant subroutine QUAD that evaluates the quadratic
                 2
        function ax  4- bx + c, where signed 16-bit arguments a, b, c, and x are passed in a table,
        named PARA, PARB, PARC, and PARK; and the output is passed in the table, named
        RESULT. The address of the table is in X when the subroutine is called. In order to
                                                                2
        demonstrate local variables, as part of your subroutine, store ax  in a 16-bit local
        variable on the stack. Write a calling sequence that writes 1, 2, 3, and 4 into PARA,
        PARB, PARC, and PARK; calls QUAD; and moves the result to global variable ANSWER.

        2 3. 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 in a table and in elements Rl and R2 and the output is passed in the same table in
        an element named RESULT. In order to demonstrate local variables, as part of your
        subroutine, store Rl times R2 in a 16-bit local variable on the stack. The address of the
        table is in X when the subroutine is called. Write a calling sequence that writes 100 into
        Rl and R2, calls PAR, and moves the result to global variable ANSWER.

        2 4. Repeat Problem 14, saving and restoring all the registers that were used.

        2 5. Repeat Problem 15, saving and restoring all the registers that were used.

        2 6. Repeat Problem 22, saving and restoring all the registers that were used.

        2 7 . Repeat Problem 23, saving and restoring all the registers that were used.

        2 8. How would the calling sequence of Figure 6.40 be modified if the subroutine SUB
        in Figure 6.41 replaced the LBRA instructions with
                              SUB     DC.W    SUBO-SUB
                                      DC.W    SUB1-SUB
                                      DC.W    SUB2-SUB

        What are the advantages of doing this, if any?
   194   195   196   197   198   199   200   201   202   203   204