To compare two character strings for greater/equal/less:
<initialize R1 to aligned QW address of string1> <initialize R2 to aligned QW address of string2> LOOP:
LDQ | R3, | 0(R1) | ; Pick up 8 bytes of string1 |
LDA | R1, | 8(R1) | ; Increment string1 pointer |
LDQ | R4, | 0(R2) | ; Pick up 8 bytes of string2 |
LDA | R2, | 8(R2) | ; Increment string2 pointer |
CMPBGE | R31, | R3, R6 | ; Test for zeros in string1 |
XOR | R3, | R4, R5 | ; Test for all equal bytes |
BNE | R6, | DONE | ; Exit if a zero found |
BEQ | R5, | LOOP | ; Loop if all equal |
DONE: CMPBGE R31, R5, R5 | ; | ||
... |
|
|
|
;At this point, R5 can be used to determine the first
;byte position (if any), and R6 can be used to determine the
;position of the terminating zero in string1 (if any).
To range-check a string of characters in R1 for ‘0’ …‘9’:
LDQ | R2, lit0s | ; Pick up 8 bytes of the character | |
|
| ; BELOW ‘0’ ‘////////’ | |
LDQ | R3, lit9s | ; Pick up 8 | bytes of the character |
|
| ; ABOVE ‘9’ ‘::::::::’ | |
CMPBGE R2, R1, R4 | ; Some R4<i>=1 if character is LT ‘0’ | ||
CMPBGE R1, R3, R5 | ; Some R5<i>=1 if character is GT ‘9’ | ||
BNE | R4, ERROR | ; Branch if some char too low | |
BNE | R5, ERROR | ; Branch if some char too high |