Page 105 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 105
82 Chapter 3 Addressing Modes
PROBLEMS
1 . Identify all instructions that have a direct mode of addressing but do not have a page
zero mode of addressing.
2 . Identify all instructions that have both direct and page zero addressing, in which the
direct addressing opcode byte is the page zero addressing opcode byte plus $20. Which
instructions have both direct and page zero addressing, in which the direct addressing
opcode byte is not the page zero addressing opcode byte plus $20?
3 . We often write a constant to an output port, which is a byte on page zero.
Compare the static and dynamic efficiency, and clarity, of the MOVB #$12, $0034
instruction to the instruction sequence LDAA #$12 STAA $ 3 4. When should you use
the MOVB instruction, and when should you use the LDAA - STAA sequence?
4. Suppose that we have a vector of 1-byte signed numbers whose first byte is at
location $840 and whose length is at location $83f and is less than 32 bytes. Write a
shortest program to search through the vector, using autoincrement addressing, putting
all those numbers that are negative and even into a vector beginning at location $860,
keeping the order of the numbers in the second vector the same as the original vector, and
putting the length of the new vector in location $85f.
5 , Suppose that we have N 16-bit two's-complement numbers stored beginning at
location $850. The two bytes of each number are stored consecutively, high byte first.
Write a shortest program, using autoincrement addressing, that puts the maximum
number in locations $84e and $84f, high byte first. Do not use "special" instructions.
The variable N is stored in location $84d. How would your program change if the
numbers were unsigned?
6. Write a shortest program that adds a 3-byte number at locations $832 through $834
to a 3-byte number at locations $835 through $837, putting the sum in locations $838
through $83a. Each number is stored high byte first and other bytes at higher addresses.
When the program finishes, condition code bits Z, N, V, and C should be set correctly.
Hint: Use just one index register to read in a byte from each number and also write out a
byte, and obtain the final condition code Z by ANDing Z bits obtained after each add.
7 . A ten-element 16-bit per element vector at location $844 is initially clear. Write a
shortest program segment that increments the vector element whose index is in
accumulator B and that is a positive integer less than 10. After the program segment is
executed several times, each vector element has a "frequency-of-occurrence" of the index.
This vector is called a histogram.
8 . Write a shortest program segment that sets a bit in a bit vector having 256 bits.
Location $856 and the following 7 bytes contain $80, $40, $20, $10, 8, 4, 2, and 1.
Index register X points to the byte that contains the leftmost (lowest-numbered) bit of
the bit vector. Bits are numbered consecutively from 0, the sign bit of the byte pointed