Page 197 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 197
174 Chapter 6 Assembly Language Subroutines
8 . 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 initialized to 100, 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 program segment, store Rl times R2 in a 32-bit
local variable on the stack.
9 . Write a position-independent reentrant subroutine QUAD that evaluates the quadratic
2
function ax + bx + c, where signed 8-bit arguments a, b, c, and x are passed in registers
A, B, (low byte of) Y, and (low byte of) X, and the output is passed in A. In order to
2
demonstrate local variables, as part of your subroutine, store ax in an 8-bit local
variable on the stack. Write a calling sequence that loads 5 into A, 2 into B, 3 into Y,
and 4 into X; calls QUAD; and stores the result in global variable ANSWER.
10. Write a shortest position-independent reentrant subroutine PAR that computes the
parallel resistance of two resistors Rl and R2, where unsigned 16-bit arguments Rl and
R2 are passed in registers D and Y and the output is passed in D. 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 loads 100 into D and Y, calls PAR, and stores
the result in global variable ANSWER.
11. 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 in global
variables PARA, PARE, PARC, and PARK and the output is passed in global variable
2
RESULT. In order to demonstrate local variables, as part of your subroutine, store ax in
a 16-bit local variable on the stack. Write a calling sequence that loads 1 into PARA, 2
into PARB, 3 into PARC and 4 into PARX; calls QUAD; and stores the result in global
variable ANSWER.
12. Write a shortest position-independent reentrant subroutine PAR that computes the
parallel resistance of two resistors Rl and R2, where unsigned 16-bit arguments Rl and
R2 are passed in global variables Rl and R2 and the output is passed in global variable
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 loads 100
into Rl and R2, calls PAR, and stores the result in global variable ANSWER.
13. Write a shortest reentrant, position-independent subroutine SEARCH that returns
the number of times that the integer K appears in the vector Z of length N and each
element is one byte. If the address of Z is in X, the value of K is in A, the value of N is
in B, and the return value NUM is left on the stack, SEARCH is called as in Figure 6.47.