-
Notifications
You must be signed in to change notification settings - Fork 0
Machine Opcodes
General-purpose registers (GPR) are a to h.
Most of the commands take GPRs as operands, few take constants or no arguments at all.
Mnemonics:
- Rx - GPR-type operand number 'x' (starting from 1)
- M[x] - memory at address 'x'
- Ux - unsigned constant number 'x'
- Sx - signed constant number 'x'
- L[n] - peripheral on line 'n'
- IP - instruction pointer register
- SP - stack pointer register
Everything is 32-bit.
Syntax given below is translated by SASM assembler into loadable binary.
Syntax: hlt
Operation: Stops Emulation
Opcode is 0x00, it makes it easier to detect bugs
Syntax: nop
Operation: Does nothing
After execution, emulation thread sleeps for 0.1 seconds
Syntax: jmp R1
Operation: IP -> R1
Syntax: ldc U1 R2
Operation: U1 -> R2
Syntax: mrm R1 R2
Operation: R1 -> M[R2]
Syntax: mmr R1 R2
Operation: M[R1] -> R2
Syntax: out R1
Operation: signal -> L[R1]
Sends signal to peripheral in given line
Syntax: jgt R1 R2
Operation: if R1 .gt 0 jmp R2
Syntax: opn
Operation: enable interrupts
When interrupts are enabled, signal from a peripheral lead to call of corresponding interrupt handler.
Syntax: cls
Operation: close interrupts
Syntax: ldr S1 R2
Operation: IP + S1 -> R2
Reads from memory from address calculated from instruction pointer and given signed constant.
Syntax: lsp R1
Operation: R1 -> SP
Syntax: push R1
Operation: R1 -> [SP++]
Stack grows from lower address to higher.
Syntax: pop R1
Operation: [SP--] -> R1
Syntax: int
Operation: INT L[0]
Causes virtual loopback device (located on line 0) to trigger an interrupt signal.
Syntax: cll
Operation: PSH IP + 4; JMP R1
Syntax: ret
Operation: JMP [SP--]
Syntax: irx
Operation: POP h-a; ret; opn
Syntax: ssp
Operation: SP -> R1
Syntax: mrr
Operation: R1 -> R2
Syntax: inv
Operation: ~R1 -> R2
Syntax: add
Operation: R1 + R2 -> R3
Syntax: sub
Operation: R1 - R2 -> R3
Syntax: mul
Operation: R1 * R2 -> R3
Syntax: div
Operation: R1 // R2 -> R3
Syntax: mod
Operation: R1 % R2 -> R3
Syntax: rsh
Operation: R1 >> R2 -> R3
Syntax: lsh
Operation: R1 << R2 -> R3
Syntax: bor
Operation: R1 | R2 -> R3
Syntax: xor
Operation: R1 ^ R2 -> R3
Syntax: band
Operation: R1 & R2 -> R3
Syntax: bpt
Operation: U1 -> external breakpoint