Selected Solutions: Appendix F
Selected Solutions: Appendix F
Selected Solutions
This is not an algorithm because the branch instruction is always taken and the program loops
indefinitely.
6.3 The following program uses DeMorgans Law to set the appropriate bits of the machine busy
register.
1
2 APPENDIX F. SELECTED SOLUTIONS
6.5 The three additions of 88 + 88 + 88 requires fewer steps to complete than the eighty eight
additions of 3 + 3 + ... + 3. Because 88 + 88 + 88 requires fewer instructions to complete, it
is faster and therefore preferable.
6.7 This program adds together the corresponding elements of two lists of numbers (vector ad-
dition). One list starts at address x300e and the other starts at address x3013. The program
finds the length of the two lists at memory location x3018. The first element of the first list is
added to the first element of the second list and the result is stored back to the first element of
the first list; the second element of the first list is added to the second element of the second
list and the result is stored back to the second element of the first list; and so on.
6.9 x3100 0010 000 0 0000 0101 ( LD R0, Z )
x3101 0010 001 0 0000 0101 ( LD R1, C )
x3102 1111 0000 0010 0001 ( L TRAP x21 )
x3103 0001 001 001 1 11111 ( ADD R1, R1, #-1 )
x3104 0000 001 1 1111 1101 ( BRp L )
x3105 1111 0000 0010 0101 ( TRAP x25 )
x3106 0000 0000 0101 1010 ( Z .FILL x5A )
x3107 0000 0000 0110 0100 ( C .FILL #100 )
6.11 This program increments each number in the list of numbers starting at address A and ending
at address B. The program tells when its done by comparing the last address it loaded data
from with the address B. When the two addresses are equal, the program stops incrementing
data values.
6.13 Memory location x3011 holds the number to be right shifted. The strategy here is to im-
plement a one bit right shift by shifting to the left 15 bits. The most significant bit must be
carried back to the least significant bit when its shifted out (a circular left shift). The data to
be shifted is stored at x3013. R1 is a counter to keep track of how many left shifts remain to
be done.
F.6. CHAPTER 6 SOLUTIONS 3