The Dauug House Wright State University logo
Dauug|36 minicomputer documentation

Miscellaneous arithmetic instructions

Opcode P/U Category Description
CMP user ALU: misc arith compare
CRF user ALU: misc arith clear R(ange) flag
MAX user ALU: misc arith maximum
MIN user ALU: misc arith minimum
NUDGE user ALU: misc arith nudge

The miscellaneous arithmetic instructions involve numeric values but do not fit any of the other categories.

CMP Compare

Syntax
cmp a - b
Register Signedness
Left unsigned or signed
Right unsigned or signed
4 opcodes total
Flag Set if and only if
N a < b
Z a = b
T flag does not change
R flag does not change

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

Syntax
crf
No registers used
1 opcode only
Flag Set if and only if
N flag does not change
Z flag does not change
T R was previously set
R never; flag is cleared

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

Syntax
c = a max b
Register Signedness
Left unsigned or signed
Right unsigned or signed
Dest. unsigned or signed
8 opcodes total
Flag Set if and only if
N maximum < 0
Z maximum = 0
T c cannot fit maximum
R T is set or R is already set

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

Syntax
c = a min b
Register Signedness
Left unsigned or signed
Right unsigned or signed
Dest. unsigned or signed
8 opcodes total
Flag Set if and only if
N minimum < 0
Z minimum = 0
T c cannot fit minimum
R T is set or R is already set

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.


Marc W. Abel
Computer Science and Engineering
College of Engineering and Computer Science
marc.abel@wright.edu
Without secure hardware, there is no secure software.
937-775-3016