User:I am islptng/SingleOperandAssembly
Jump to navigation
Jump to search
Instructions
The RISC has 16 instructions, each of them has exactly 1 operand.
The computer has a register to store the result of calculations.
| Hex | Keyword | Meaning |
|---|---|---|
| 0 | imd x | reg = x |
| 1 | jmp x | pc = x |
| 2 | jnz x | if(reg != 0) pc = x |
| 3 | jlz x | if(reg < 0) pc = x |
| 4 | get x | reg = ram[x] |
| 5 | put x | ram[x] = reg |
| 6 | rget x | reg = ram[ram[x]] |
| 7 | rput x | ram[ram[x]] = reg |
| 8 | add x | reg += ram[x] |
| 9 | sub x | reg -= ram[x] |
| A | and x | reg &= ram[x] |
| B | or x | reg |= ram[x] |
| C | xor x | reg ^= ram[x] |
| D | rol x | (reg >> (8 - ram[x])) |
| E | shr x | reg >>= ram[x] (logic) |
| F | ashr x | reg >>= ram[x] (arithmetic) |
Virtual machine and assembler
Try it online! Use a single line of exclamation mark to separate the assembly code and input.
Example for a cat program Input:
w:get 65535 put 65535 jnz w ! 3 0
Assembly code:
w:get 65535 put 65535 jnz w
Input for the machine:
[3,0]
Assembled to machine code:
0000 4 ffff 0001 5 ffff 0002 2 0000
Output result:
3 0