Implemented memory and arithmetic instructions
This commit is contained in:
parent
a098a30da0
commit
efc263fe72
28
creature.go
28
creature.go
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user