Page 107 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 107
84 Chapter 3 Addressing Modes
1 5. Write a shortest program segment beginning at $866 to call subroutine PRINT, at
$852, with the address of the character string to be printed in index register X, first for a
string stored at location $876 and then for one at $893. However, the calling program
segment, the subroutines, and the strings may be in a single ROM that can be installed
anywhere in memory. They are in locations fixed relatively with respect to each other
(position independence). Show your machine code.
16. Write a shortest program segment to put square waves on each output port bit, at
1
location 0 so bit i's square wave's period is 2 times the period of bit O's square wave.
17. Write a shortest program segment to add index register X to accumulator D,
transferring the data on the auxiliary stack pointed to by Y, as shown in Figure 3.11.
18. Write a shortest program segment to exclusive-OR accumulator A into accumulator
B, transferring the data on the auxiliary stack pointed to by Y, as shown in Figure 3.11.
19. The Fibbonacci number of 0, ^F(O) is 1, and ^F(l) is 1, otherwise ?(i) is ?(i - 1)
+ J(i - 2) for any positive integer i. Write a subroutine FIB that computes the
Fibbonacci number; the input i is in index register X and the result f(i ) is left in
accumulator D.
(a) Write a recursive subroutine, (b) Write a nonrecursive (loop) subroutine.
20. Write a subroutine POWER, with input signed number n in accumulator D and
m
unsigned number m in index register X that computes n leaving the result in
accumulator D.
(a) Write a recursive subroutine, (b) Write a nonrecursive (loop) subroutine.
21. In Figure 3.16a, the instruction MOVW #$ 18bc, 1, SP writes to a local variable
on the stack in the outer loop. Write an instruction to load this value into index register
X, which is just inside the next inner loop, where the instruction LDAA 2, SP is. Write
an instruction to load this value into index register X, which is just inside the innermost
loop, where the instruction LDAA 6, SP is.
2 2. Assume that an overflow error can occur in an ADD instruction in the innermost
loop in Figure 3.16a, just after the instruction LDAA 6, SP. The following instruction
BVS L, after the ADD instruction, will branch to location L. Write an instruction at this
location L to deallocate stacked local variables such that the stack pointer will be exactly
where it was before the first instruction of this figure, LEAS -3,SP, was executed.
2 3. Write a shortest subroutine that compares two n-character null (0) terminated
ASCII character strings, si and s2, which returns a one in accumulator B if the strings
are the same and zero otherwise. Initially, X points to the first member of si (having the
lowest address), Y points to the first member of s2, and n is in accumulator A.
24. Figure 3.21 shows a table where the first column is a 32-bit Social Security
number; other columns contain such information as age; and each row, representing a
person, is 8-bytes wide. Data for a row are stored in consecutive bytes. Write a shortest
program segment to search this table for a particular social security number whose high
16 bits are in index register Y, whose low 16 bits are in accumulator D, and for which X
contains the address of the first row minus 8. Assume that a matching Social Security
number will be found. Return with X pointing to the beginning of its row.