Page 336 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 336
PROBLEMS 3! 3
13. Write the shortest subroutines necessary to maintain five 8-element one-byte
element queues, where each queue is in a buffer. Your implementation should include a
branch to location ERROR if an overflow of the buffer to hold the strings occurs. The
first queue is stored at label Ql; the second, at Q2, etc. Upon entering the subroutines,
the address of the queue being used is in X and the data is passed in ACCA.
14. Write a subroutine BUILD, which is passed, by name, a string of ASCII lower-
case letters terminated by a carriage return, to form the linked list shown in Figure 10.9.
15. What is the limitation on the number of characters in the tree for the subroutine of
Figure it). 10? How would you change the subroutine to allow for 350 characters?
16. Write the subroutine REVSCAN that corresponds to SCAN but that now scans the
tree from the right, printing the characters out in reverse alphabetical order.
17. Write a subroutine to add M 4-byte numbers that corresponds to the following
header:
* SUBROUTINE ADD4
*
* ADD4 adds the M 4-byte numbers pointed to by Z Placing
* the result in SUM. All parameters are passed on the
* stack with the sequence
*
* LDAB M ; Value of M into B
* LEAX Z,PCR ; Address of Z into X
* LEAY SUM, PCR ; Address of SUM into Y
* PSHY
* PSHX
* PSHB
* BSR ADD4
* LEAS 5,SP ; Balance stack
1 8. Write a position-independent reentrant subroutine to go with the header:
*
* SUBROUTINE INSERT inserts the string STG into string TEXT at the first
* occurrence of the ASCII letter SYMBOL. No insertion is made if SYMBOL does not
* occur in TEXT. Parameters are passed on the stack with the sequence
*
* LDAA SYMBOL ; ASCII symbol into A
* LDAB LSTG ; Length of STG into B
* PSHD ; Push both parameters
* MOVW #STG,2,-SP ; Push Address of STG
* LDAB LTEXT ; Length of TEXT into B
* PSHB ; Push parameter
* MOVW #TEXT,2,-SP ; Push Address of TEXT
* BSR INSERT ; Subroutine balances the stack