py_register_machine2.commands.basic_commands: The most important commands
mnemonic | opcode | Description |
---|---|---|
mov a b | 0x01 | copy content from register a to register b [1] |
pld a b | 0x02 | load from address in register a to register b [1] |
pst a b | 0x03 | store register a to address in register b [1] |
ld a b | 0x04 | load from a into register b [1] |
st a b | 0x05 | store from register a to address b [1] |
add a b | 0x06 | b = a + b |
sub a b | 0x07 | b = a - b |
mul a b | 0x08 | b = a * b |
div a b | 0x09 | b = a / b (integer division) |
jmp a | 0x0a | pc = pc + a - 2 [3] |
in a b | 0x0b | read from address in register a to register b [2] |
out a b | 0x0c | write register a to address in register b [2] |
inc a | 0x0d | increase register a |
dec a | 0x0f | decrease register a |
jne a b | 0x10 | if a != 0: pc += b - 3 |
jeq a b | 0x11 | if a == 0: pc += b - 3 |
jle a b | 0x12 | if a <= 0: pc += b - 3 |
jlt a b | 0x13 | if a < 0: pc += b - 3 |
jge a b | 0x14 | if a >= 0: pc += b - 3 |
jgt a b | 0x15 | if a > 0: pc += b - 3 |
ldi a b | 0x16 | Load immediate a into Register b |
sjmp a | 0x17 | pc = a - 2 [3] |
[1] | (1, 2, 3, 4, 5) stores and loads to/from the memory BUS |
[2] | (1, 2) reads and writes from/to the device BUS |
[3] | (1, 2) both the fetch opcode and fetch arguments increases the PC, so we need to undo this. |
A list of all commands is basic_commands
.
py_register_machine2.commands.stack_based: A bunch of stack based commands
mnemonic | opcode | Description |
---|---|---|
push a | 0x18 | *(SP–) = a |
pop a | 0x19 | a = *(++SP) |
call a | 0x1a | *(SP–) = PC; PC += a |
scall a | 0x1b | *(SP–) = PC; PC = a |
ret | 0x1c | PC = *(++SP) |
all stackbased commands are available in the list stack_based_commands
.
py_register_machine2.commands.gym_bav_16: Instruction set compatible to the register machine used in the bavarian gymnasium.
mnemonic | opcode | Description |
---|---|---|
DLOAD c | 0x01 | A = c (c is a number) |
LOAD r | 0x02 | A = r (r is a register) |
STORE r | 0x03 | r = A |
ADD r | 0x04 | A = A + r (r is a register) |
SUB r | 0x05 | A = A - r |
MULT r | 0x06 | A = A * r |
DIV r | 0x07 | A = A / r |
JUMP c | 0x08 | PC = c (c is a constant) |
HALT | 0x09 | ECR = 1 (halts the engine) |
JNE c | 0x0a | if(A != 0): PC = c |
JEQ c | 0x0b | if(A == 0): PC = c |
JLT c | 0x0c | if(A < 0): PC = c |
JLE c | 0x0d | if(A <= 0): PC = c |
JGT c | 0x0f | if(A > 0): PC = c |
JGE c | 0x10 | if(A >= 0): PC = c |
all commands are available in the list commands
Note:
Actually all commands use 2 words. So actually all branch functions set
the PC to c * 2
.