Implemented mod, halt, and jump instructions

This commit is contained in:
Sasha Koshka 2022-08-28 17:11:43 -04:00
parent 589657e31b
commit 4067027588
1 changed files with 18 additions and 0 deletions

View File

@ -91,8 +91,26 @@ func (machine *Machine) Execute (offset int) {
machine.Push(notEqual)
case 0xc:
// MOD
// performs a modulo operation of the second to last
// word on the stack to the last word on the stack
machine.Push(machine.Pop() % machine.Pop())
case 0xd:
// HALT
// stops execution
return
case 0xe:
// JMP
// jump to the address specified by the last word on the
// stack if the second to last word on the stack is
// nonzero
jumpTo := machine.Pop()
if machine.Pop() != 0 {
machine.counter = jumpTo - 1
}
case 0xf:
}
machine.counter ++