cmp2
Compare register against bounds
Compares a register with a lower and an upper bound and sets the flags, with C set when it is outside them.
Sizes .b .w .l, .w by default68020 only: select opt p=68020 before any code or data
- ● set from the result
- – not changed
Forms
Operands
<ea>- An operand using one of the addressing modes listed for this form. The list determines whether it can be a register, memory or an immediate value. With
opt p=68020, an allowedd(An,Xn)ord(PC,Xn)mode also permits the corresponding 68020 indexed and memory indirect forms. See 68020 addressing. More Rn- A data or address register,
d0tod7ora0toa7. More
The memory operand names two consecutive bounds, lower first, each stored at the instruction’s size. A data register is compared at that size. An address register is compared as a full long, with byte or word bounds sign-extended to long. Both endpoints are included in the range.
Interpret the bounds and value as signed numbers. If the lower bound is at or below the upper bound, the range includes every value between them. If the lower bound is above the upper bound, the range wraps: a value is in range when it is at or above the lower bound, or at or below the upper bound. For example, dc.b 16, 240 stores the signed bounds 16 and -16. Its accepted byte values are 16 through 127 and -128 through -16, which are the unsigned values 16 through 240.
Z is set when the value equals either bound and cleared otherwise. C is set outside the range and cleared inside it. N and V are undefined, and X is unchanged. Use bcs after the comparison to branch on an out-of-range value. chk2 performs the same comparison and also raises an exception when the value is outside.
opt p=68020
* --- Count the digits in a string ---
lea text, a0
moveq #0, d1 ; the count
next:
move.b (a0)+, d0
beq END ; the 0 that ends the string
cmp2.b digits, d0 ; C is set when d0 is not from '0' to '9'
bcs next
addq.l #1, d1 ; at the end, d1 = 3
bra next
text:
dc.b 'a1b22cd', 0
digits:
dc.b '0', '9' ; the lower bound, then the upper one
END: