Page 400 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 400
PROBLEMS 377
PROBLEMS
1. Write an 6811 subroutine DOTPRD that passes parameters after the call as that
subroutine was written in Figure 6.25. It should be reentrant, position independent, and
as short as possible.
2. Write a shortest 6811 subroutine SRCH that finds a string of ASCII characters in a
text. The label STRNG is the address of the first letter of the string, STLEN is the length
of the string, TXT is the address of the first letter of the text, TXLEN is the length of the
text, and the subroutine will exit with C = 1 and the address of the first occurrence of the
first letter of the string in the text in X, if it is found, or C = 0 if it is not found.
3 . Write a position-independent reentrant 6811 subroutine QUAD that evaluates the
2
quadratic function ax + bx + c, where unsigned 8-bit arguments a, b, c, and x are passed
on the stack from low to high addresses respectively, named PARA, PARE, PARC, and
PARX, and the output is returned in register B. In order to demonstrate local variables, as
2
part of your subroutine, store ax in an 8-bit local variable on the stack. 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.
4. Write a shortest position-independent reentrant 6811 subroutine PAR that
computes the parallel resistance of two resistors Rl and R2, where unsigned 8-bit
arguments are passed on the stack and named Rl and R2, and the output is returned in
register B. In order to demonstrate local variables, as part of your subroutine, store Rl
times R2 in a 16-bit local variable on the stack. Write a calling sequence that writes 100
into Rl and R2, calls PAR, and moves the result to global variable ANSWER.
5 . Write a shortest reentrant 6808 SWI interrupt handler AAX that will add A to X.
6 . Write a shortest reentrant 6808 SWI interrupt handler EMUL that will multiply A
by HX, putting the result in HX, exactly as the 6812 EMUL works. Ignore CC bits,
7 , Write a position-independent reentrant 6808 subroutine QUAD that evaluates the
2
quadratic function ax + bx + c, where unsigned 8-bit arguments a, b, c, and x are passed
on the stack from low to high addresses respectively, named PARA, PARB, PARC, and
PARX, and the output is returned in register A. In order to demonstrate local variables, as
2
part of your subroutine, store ax in an 8-bit local variable on the stack. 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.
8 . Write a shortest position-independent reentrant 6808 subroutine PAR that computes
the parallel resistance of two resistors Rl and R2, where unsigned 8-bit arguments are
passed on the stack, and named Rl and R2, and the output is returned in register B. In
order to demonstrate local variables, as part of your subroutine, store Rl times R2 in an
16-bit local variable on the stack. Write a calling sequence that writes 100 into Rl and
R2, calls PAR, and moves the result to global variable ANSWER.
9 . Write a shortest reentrant MC6805 SWI interrupt handler PSHX that will push X
on the stack as the 6811 instruction PSHX works. Assume the location of SWI is at
$281. This instruction must be reentrant.

