Page 401 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 401
378 Chapter 12 Other Microcontrollers
10. Write a shortest 6805 subroutine MOVE that can move any number of words from
any location to any other location in memory. The calling sequence will put the
beginning address of the source in page-zero global variable SRC, the beginning address
of the destination in DST, and the length in LEN. Use impure coding if necessary.
11. Write a position-independent reentrant 6805 subroutine QUAD that evaluates the
2
quadratic function ax + bx + c, where unsigned 8-bit arguments a, b, c, and x are passed
as globals named PARA, PARE, PARC, and PARK, and the output is returned in register
A. In order to demonstrate the absence of local variables, as part of your subroutine, store
2
ax in an 8-bit global variable TEMP. Write a calling sequence that writes 1, 2, 3, and 4
into PARA, PARE, PARC, and PARK, calls QUAD, and moves the result to global
variable ANSWER.
1 2. Write a shortest position-independent reentrant 6805 subroutine PAR that computes
the parallel resistance of two resistors Rl and R2, where unsigned 8-bit arguments are
passed as globals named Rl and R2, and the output is returned in register A. In order to
demonstrate the absence of local variables, as part of your subroutine, store Rl times R2
in a 16-bit global variable TEMP. Write a calling sequence that writes 100 into Rl and
R2, calls PAR, and moves the result to global variable ANSWER.
13. Write a shortest 6805 program segment that will jump to subroutines LO to L7
depending on the value of X. If (X) = 0, jump to subroutine LO; if (X) = 1, jump to
subroutine LI, and so on. Assume that there is a table JTBL as shown below:
JTBL DC.W LO, LI, L2, L3, L4, L5, L6, L7
Use self-modifying code if necessary.
14. Write a shortest 6805 subroutine to divide the unsigned number in X by the
unsigned number in A, leaving the quotient in X and the remainder in A. Use only
TEMPI and TEMP2 to store variables needed by the subroutine.
15. Write a shortest 6805 subroutine to clear bit n of a 75-bit vector similar to the
SET in Problem 8 in Chapter 3. The instruction BCLR N,M clears bit N of byte M and
has opcode $ 11 + 2 * N followed by offset M. Use self-modifying code.
16. Write an 6805 subroutine to transmit the bits of the 75-bit vector set by SET
described in Problem 8 in Chapter 3, bit 0 first, serially through the least-significant bit
of output port A at location 0. Each time a bit is sent out, the second-least-significant
bit of that output port is pulsed high and then low. The least-significant bit happens to
be connected to a serial data input, and the second-least-significant bit is connected to a
clock of a shift register that controls display lights.
17. Write a shortest 68300 series subroutine CLRREG to clear all the registers except
A7. Assume that there is a block of 60 bytes of zeros, after LOCO, that is not in part of
your program (i.e., use 32-bit direct addressing, and do not count these bytes when
calculating the length of your subroutine). Be careful, because this one must be checked
out, and the obvious solutions do not work.

