Implemented memory and arithmetic instructions

This commit is contained in:
Sasha Koshka 2022-08-28 16:56:28 -04:00
parent a098a30da0
commit efc263fe72
1 changed files with 28 additions and 0 deletions

View File

@ -28,11 +28,39 @@ func (machine *Machine) Execute (offset int) {
machine.Pop()
case 0x2:
// LOAD
// push the word at an address onto the stack
machine.Push(machine.Peek(machine.Pop()))
case 0x3:
// STOR
// store a word at an address
machine.Poke(machine.Pop(), machine.Pop())
case 0x4:
// ADD
// adds the last two words on the stack
machine.Push(machine.Pop() + machine.Pop())
case 0x5:
// SUB
// subtracts the last two words on the stack
right := machine.Pop()
left := machine.Pop()
machine.Push(left - right)
case 0x6:
// MUL
// multiplies the last two words on the stack
machine.Push(machine.Pop() * machine.Pop())
case 0x7:
// DIV
// divides the last two words on the stack
right := machine.Pop()
left := machine.Pop()
machine.Push(left / right)
case 0x8:
case 0x9:
case 0xa: