# RiscEmu: Instructions

## Register Instructions (index)

• `ADD a b cR.a = R.b + R.c`

• `SUB a b cR.a = R.b - R.c`

• `MUL a b cR.a = R.b * R.c`

• `DIV a b cR.a = R.b DIV R.c`

• `MOD a b cR.a = R.b MOD R.c`

• `CMP a b cR.a = R.b - R.c`
When the difference is outside the range -231 <= x-y < 231, CMP yeilds a result with the wrong magnitude but with the correct sign

• `OR a b cR.a = R.b OR R.c`

• `AND a b cR.a = R.b & R.c`

• `BIC a b cR.a = R.b & ~ R.c`

• `XOR a b cR.a = R.b XOR R.c`

• `LSH a b cR.a = LSH(R.b R.c)`

• `ASH a b cR.a = ASH(R.b R.c)`

• `CHK a c0 <= R.a < R.c`

• `ADDI a b cR.a = R.b + c`

• `SUBI a b cR.a = R.b - c`

• `MULI a b cR.a = R.b * c`

• `DIVI a b cR.a = R.b DIV c`

• `MODI a b cR.a = R.b MOD c`

• `CMPI a b cR.a = R.b - c`
When the difference is outside the range -231 <= x-y < 231, CMP yelds a result with the wrong magnitude but with the correct sign

• `ORI a b cR.a = R.b OR c`

• `ANDI a b cR.a = R.b & c`

• `BICI a b cR.a = R.b & ~ c`

• `XORI a b cR.a = R.b XORI c`

• `LSHI a b cR.a = LSH(R.b c)`

• `ASHI a b cR.a = ASH(R.b c)`

• `CHKI a c0 <= R.a < c`

• `ADDIU a b cR.a = R.b + c` (unsigned)

• `SUBIU a b cR.a = R.b - c` (unsigned)

• `MULIU a b cR.a = R.b * c` (unsigned)

• `DIVIU a b cR.a = R.b DIV c` (unsigned)

• `MODIU a b cR.a = R.b MOD c` (unsigned)

• `CMPIU a b cR.a = R.b - c` (unsigned)

• `ORIU a b cR.a = R.b OR c` (unsigned)

• `ANDIU a b cR.a = R.b & c` (unsigned)

• `BICIU a b cR.a = R.b & ~ c` (unsigned)

• `XORIU a b cR.a = R.b XORI c` (unsigned)

• `CHKIU a c0 <= R.a < c` (unsigned)

• `LDW a b cR.a = Mem[R.b + c]`

• `LDB a b cR.a = Mem[R.b + c]`

• `POP a b cR.a = Mem[R.b]; R.b = R.b + c`
pop stack

• `STW a b cMem[R.b + c] = R.a`
store word

• `STB a b cMem[R.b + c] = R.a`
store byte

• `PSH a b cR.b = R.b - c; Mem[R.b] = R.a`
push stack

## Control Instructions (index)

• `BEQ a c`
Branch to `c` if `R.a = 0`

• `BNE a c`
Branch to `c` if `R.a # 0`

• `BLT a c`
Branch to `c` if `R.a "<" 0`

• `BGE a c`
Branch to `c` if `R.a >= 0`

• `BLE a c`
Branch to `c` if `R.a <= 0`

• `BGT a c`
Branch to `c` if `R.a > 0`

• `BSR c`
Save `PC` in `R31`, then branch to `c` (address `PC` relative)

• `JSR c`
Save `PC` in `R31`, then jump to `c` (address absolute)

• `RET c`
Jump to address in `R.c` (address absolute)

## Special Instructions (index)

• `RD aR.a = `input

• `WRD c`prints `R.c`

• `WRH c`prints `R.c`

• `WRL`prints a newline

## Notes (index)

• The immediate field `c` is 16 bit wide
unsigned: -215 <= c < 215
signed: 0 <= c < 216

Matteo Corti