| R-Format | I-Format | code | description | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| signed | unsigned | signed | unsigned | ||||||||||||||||||||||||||||||||
cmpeq| cmpeqi | == | a equals b
| cmpne | cmpnei | != | a not equal to b
| cmplt | cmpltu | cmplti | cmpltui
| < | a less than b
| cmpgt | cmpgtu
| cmpgti | cmpgtui
| > | a greater than b
| cmple | cmpleu
| cmplei | cmpleui
| <= | a not greater than b
| cmpge | cmpgeu | cmpgei | cmpgeui
| >= | a not less than b
| | ||||
| pseudo-instruction |
cmplt rC, rA, rB
|
|
if (signed) rA < (signed) rB | then rC ← 1 else rC ← 0 cmplti rB, rA, IMM16
|
|
if (signed) rA < (signed) se(IMM16) | then rB ← 1 else rB ← 0 cmpltu rC, rA, rB
|
|
if (unsigned) rA < (unsigned) rB | then rC ← 1 else rC ← 0 cmpltui rB, rA, IMM16
|
|
if (unsigned) rA < (unsigned) {0x0000,
IMM16} | then rB ← 1 else rB ← 0 | ||||||||||||
| control | inst | code | description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 00 | cmpeq
| == | a equals b
| 01 | cmpne
| != | a not equal to b
| 10 | cmplt
| < | a less than b
| 11 | cmpge
| >= | a not less than b
| |
Set ALU control for either signed subtraction (001) or unsigned subtraction (011), depending on the value of control[2]. Then check the status of the result:
cmp = (control[1]? neg: zero)^control[0];
control[2]?
control[4:0]| operation
| 00xxx | ALU operations
| 010xx | compare, signed
| 011xx | compare, unsigned
| 10xxx | shift
| 11xxx | shift - immediate
| |
|---|
control[4:3] is the data multiplexer control.
Maintained by John Loomis, last updated 24 October 2008