chk
Check register against bounds
Checks whether a data register is between zero and an upper bound, with both endpoints included.
XNZVC –????
- ? undefined (do not rely on it)
- – not changed
- N Defined only when the CHK exception is raised: set if the register is below zero, cleared if it is above the bound.
Forms
68020 only
These forms require the 68020. Select opt p=68020 before any code or data.
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 Dn- A data register,
d0tod7. More #imm- An immediate value written after
#: a number, character or label, such as#10,#$FFor#'a'. It must fit the operation’s size: byte-128to255, word-32768to65535, or long-2147483648to4294967295; signed and unsigned spellings are accepted. More
chk.w reads the bound and the register’s low word as signed words. A value below zero or above the bound raises a CHK exception through vector 6 at $18. The handler returns to the instruction after chk with rte. N is set for a value below zero and cleared for a value above the bound. Z, V and C are undefined by the instruction and may change. X is unchanged.
Without a handler, the program ends at chk. See writing a handler. On the 68020, chk.l checks the whole register against a signed long bound. chk2 lets you supply both bounds.
* --- Keep an index between 0 and 9 ---
move.l #out_of_range, $18 ; vector 6 is at $18
moveq #4, d0
chk #9, d0 ; 4 is in range: nothing happens
moveq #12, d0
chk #9, d0 ; 12 is above 9: out_of_range runs
move.w d0, d1 ; rte comes back here: d1 = 9
bra END
out_of_range:
moveq #9, d0 ; use the last index instead
rte
END: