CHAPTER FIVE
SORTING
EXERCISES
[6]
6. [15] Mr. B. C. Dull (an MMIX
programmer) wanted to know if the number stored in location A
is greater than, less than, or equal to the number stored in location B
. So he wrote ‘LDO $0,A; LDO $1,B; SUB $2,$0,$1
’ and tested whether register $2
was positive, negative, or zero. What serious mistake did he make, and what should he have done instead?
7. [17] Write an MMIX
subroutine MCmp
for multiprecision comparison of n-byte keys (an−1, . . . , a0) and (bn−1, . . . , b0), where ai and bi are unsigned bytes stored in order of increasing index i. Use the following specification:
Calling sequence: | PUSHJ t,MCmp |
Entry conditions: | $0 ≡ n; $1 ≡ LOC (a0); and $2 ≡ LOC (b0) |
Return value: | 1, if (an–1, . . . , a0) < ... |
Get The MMIX Supplement: Supplement to The Art of Computer Programming Volumes 1, 2, 3 by Donald E. Knuth now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.