Page 134 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 134
PROBLEMS 111
13. Write a shortest assembly-language (source code) subroutine that concatenates one
null-terminated string onto the end of another null-terminated string, storing a null at the
end of the expanded string. Assume that on entry, X points to the first string, Y points
to the second string, and there is enough space after the second string to fit the first
string into this space. This program is essentially the C procedure strcat().
14. Write a shortest assembly-language (source code) subroutine to compare at most n
characters of one null-terminated string to those of another null-terminated string, similar
to Figure 4.10. Assume X points to the first string, and Y points to the second string,
and A contains the number n. Return carry set if and only if the strings match.
15. Write a shortest assembly-language (source code) subroutine that builds a symbol
table as in Figure 4.12a but stores six-letter symbolic names and a two-byte value in
each symbol table row. Upon entry to the subroutine, X points to the first of the six
letters (the other letters follow in consecutive locations), and accumulator D contains the
two-byte value associated with this symbol. The symbol table is stored starting at label
LABELS, and the number of symbols (rows) is stored in one-byte variable SIZE.
16. Write a shortest assembly-language (source code) subroutine that searches a symbol
table as in Figure 4.12b but searches six-letter symbolic names having a two-byte value
in each symbol table row. Upon entry to the subroutine, X points to the first of the six
letters (the other letters follow in consecutive locations). The symbol table is stored
starting at label LABELS, and the number of symbols (rows) is stored in one-byte
variable SIZE. The subroutine returns with carry bit set if and only if a matching
symbol is found; then Y points to the beginning of the row where the symbol is found.
17 . Write a shortest assembly-language (source code) program that finds the maximum
MAX of N 4-byte signed numbers contained in array Z where N < 100. Your program
should have in it the assembler directives
N DS 1
MAX DS 4
Z DS.L 100
and be position independent. How would your program change if the numbers were
unsigned?
18. Write an assembly-language program that finds the sum SUM of two 4-byte signed
magnitude numbers NUM1 and NUM2. The result should also be in signed-magnitude
form. Your program should include the assembler directives
ORG $800
N DS 1
NUM1 DS 4
NUM2 DS 4
SUM DS 4