cmprb
Compare Ranged Byte
Compares a byte value in one register to see if it falls within a range defined by another register.
Details
Compares a byte value from RA against a range defined by two bytes in RB, setting the Condition Register field BF with the comparison result. The L field controls whether the comparison is unsigned (L=0) or signed (L=1). The instruction writes only the specified CR field; CR0 is not affected unless BF designates CR0.
Pseudocode Operation
byte_val ← RA[56:63]
range_low ← RB[56:63]
range_high ← RB[48:55]
if L == 0 then
// unsigned comparison
result ← (byte_val >= range_low) & (byte_val <= range_high)
else
// signed comparison
result ← (byte_val[signed] >= range_low[signed]) & (byte_val[signed] <= range_high[signed])
CR[BF] ← (result, 0, 0, 0)
Programming Note
cmprb is useful for implementing character typing functions such as isalpha(), isdigit(), isupper(), and islower() that are implemented using one or two range compares of the character. A single-range compare can be implemented with an addi to load the upper and lower bounds in the range, such as isdigit(). A combination of addi-addis can be used to set up 2 ranges, such as for isalpha().
Example
Encoding
Operands
-
BF
CR Field -
L
Mode -
RA
Byte -
RB
Range -
RT
Target General Purpose Register