Page 200 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 200
PROBLEMS 1.77
29. A device driver is an operating system component that interfaces to an I/O device.
It has subroutines Init, Read, Write, and Terminate. Subroutine Init is called when the
I/O device is being prepared for use, Subroutine Read is called to read data from the I/O
device, Subroutine Write is called to output data from the I/O device, and Subroutine
Terminate is called when the I/O device is no longer needed. Write a program segment for
the beginning of a position-independent device driver, which, for an address in index
register X, JSR 0, X always executes the Init subroutine; JSR 4, X always executes
the Read subroutine; JSR 8,X always executes the Write subroutine; and JSR 16,X
always executes the Terminate subroutine, regardless of where the device driver is stored.
3 0. Write an instruction sequence that produces the same moves as the instruction SWI
and, in addition, sets the bits in the CC register in exactly the same way.
31. Write a shortest trap handler whose opcode is $1830, to test whether a 2-byte
number N is prime. The number N should be passed by value in D and the carry bit
should be returned set if N is prime. Write a program segment that loads 11 into D,
executes $1830, and branches if carry set to location ISPRIME.
32. Write a shortest trap handler whose opcode is $1831 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, Y, and X, and the 16-bit output is passed in A. In order to demonstrate local
2
variables, as part of your handler, store ax in an 8-bit local variable on the stack. Write
a program segment that loads 1 into A, 2 into B, 3 into Y, and 4 into X; executes
$1831; and stores the result in global variable ANSWER.
3 3. Write a trap handler whose opcode is $1832, 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 16-bit output is passed in D. In order to demonstrate local
variables, as part of your handler, store Rl times R2 in a 32-bit local variable on the
stack. Write a program segment that loads 100 into D and Y, executes $1832, and stores
the result in global variable ANSWER.
34. Write a position-independent trap handler, whose address is in $FFF8, which
branches to address PRIME if the trap instruction is $1830, to address QUAD if the trap
instruction is $1831, and to address PAR if the trap instruction is $1832.