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

PROBLEMS                                                             173


                                      PROBLEMS

                                                                  2
        1. Write a program segment that evaluates the quadratic function ax  + bx + c, where
        signed 16-bit arguments a, b, c, and x are stored on the stack and are initialized to 1, 2,
        3, and 4, respectively, by pushing 4, then 3, then 2, and then 1, in the manner of Figure
        6.6, and the output is stored on the stack in a "hole" created by a LEAS ~2, SP
        instruction before the segment begins. In order to demonstrate local variables, as part of
                                            2
        your program segment, save 16-bit value ax  in a 16-bit local variable on the stack,
        2 . Write a shortest program segment that computes the parallel resistance of two
        resistors Rl and R2, where unsigned 16-bit arguments Rl and R2 are stored in local
        variables, which are both initialized to 100, by pushing 100 and then 100, and the result
        is stored on the stack in a "hole" created by a LEAS -2, SP instruction, in the manner
        of Figure 6.6. In order to demonstrate local variables, as part of your program segment,
        store Rl times R2 in a 32-bit local variable on the stack.

                                                                  2
        3 . Write a program segment that evaluates the quadratic function ax  + bx + c, where
        signed 16-bit arguments a, b, c, and x are stored in local variables PARA, PARE, PARC,
        and PARK on the stack, which are initialized to 1, 2, 3, and 4, respectively, and the
        output is returned in local variable RESULT on the stack, in the manner of Figure 6.JO.
                                                                           2
        In order to demonstrate local variables, as part of your program segment, store ax  in a
         16-bit local variable on the stack.
        4 , Write a shortest program segment that computes the parallel resistance of two
        resistors Rl and R2, where unsigned 16-bit arguments are stored in local variables named
        Rl and R2, which are both initialized to 100 and the output is returned in register D, in
        the manner of Figure 6.10. In order to demonstrate local variables, as part of your
        program segment, store Rl times R2 in a 32-bit local variable on the stack.
                                                                  2
        5 . Write a program segment that evaluates the quadratic function ax  + bx + c, where
        signed 16-bit arguments a, b, c, and x are stored in local variables PARA, PARE, PARC,
        and PARX on the stack as outer segment local variables, which are initialized to 1, 2, 3,
        and 4, respectively, and the output is returned in register D, in the manner of Figure
        6.13. In order to demonstrate local variables, as part of your inner program segment,
               2
        store ax  in a 16-bit local variable on the stack.
        6 . Write a shortest program segment that computes the parallel resistance of two
        resistors Rl and R2, where unsigned 16-bit arguments are stored in outer segment local
        variables Rl and R2, which are both intitilaized to 100, and the output is returned in
        register D, in the manner of Figure 6.13. To demonstrate local variables, as part of your
        inner program segment, store Rl times R2 in a 32-bit local variable on the stack.

                                                                  2
        7 . Write a program segment that evaluates the quadratic function ax  + bx + c, where
        signed 16-bit arguments a, b, c, and x are stored in local variables PARA, PARE, PARC,
        and PARX on the stack as outer segment local variables, which are initialized to 1, 2, 3,
        and 4, respectively, and the output is returned in register D, using a stack marker in the
        manner of Figure 6.14. In order to demonstrate local variables, as part of your inner
                              2
        program segment, store ax  in a 16-bit local variable on the stack.
   191   192   193   194   195   196   197   198   199   200   201