Miscellaneous arithmetic instructions
The miscellaneous arithmetic instructions involve numeric values but do not fit any of the other categories.
CMP
Compare
This instruction subtracts the right operand from the left and sets the N
and Z
flags according to the result. These flags will be correct for any combination of inputs; there is no overrange situation that can occur. The result is discarded, and the T
and R
flags do not change.
The required −
in the syntax serves as a semantic reminder for the programmer.
CRF
Clear R
(ange) flag
CRF
and REVERT
are the only nonprivileged instructions that can clear the R
(ange) flag. CRF
copies the R
flag to T
, and then R
is cleared. Here is a code example for how to save and restore the R
flag:
unsigned save_R
; save R flag
crf ; previous R now in T
save_R = 0 ++ 0 ; add with carry saves T
; restore R flag
crf ; R is now clear
save_R = 0 - save_R ; possible overflow restores R
MAX
Maximum
The maximum of the two operands is determined, and the N
and Z
flags are set accordingly. The 36 least significant bits of the maximum are stored in the destination register, which may be signed or unsigned. Flags T
and R
are set if the full maximum does not fit, otherwise T
is cleared and R
is left unchanged.
MIN
Minimum
The minimum of the two operands is determined, and the N
and Z
flags are set accordingly. The 36 least significant bits of the minimum are stored in the destination register, which may be signed or unsigned. Flags T
and R
are set if the full minimum does not fit, otherwise T
is cleared and R
is left unchanged.
NUDGE
Nudge
NUDGE
replaces the rightmost 0–35 bits of a
with the same number of bits from b
, and writes the result to c
. The number of bits replaced is the number that appear to the right of the leftmost one in b
. In essence, the first one bit as b
is scanned from left to right is the start bit, with all bits following that bit replacing the bits in the corresponding positions of a
. For example:
x = 1101_0110`b nudge 0010_1101`b ; x becomes 1100_1101`b.
NUDGE
is useful for altering the modulus of a number relative to some power of two without first examining the number. This makes NUDGE
also useful for efficiently converting a pointer to a member of a power-of-two-sized structure to a pointer to any other member of the same structure, without needing to know or find out which member was indicated by the original pointer.
NUDGE
is also useful for rounding down to a power-of-two boundary without an AND
mask.