Implemented comparison instructions

This commit is contained in:
Sasha Koshka 2022-08-28 17:03:15 -04:00
parent a1ea9f30da
commit 589657e31b
1 changed files with 25 additions and 1 deletions

View File

@ -60,12 +60,36 @@ func (machine *Machine) Execute (offset int) {
machine.Push(machine.Pop() / machine.Pop())
case 0x8:
// EQU
// EQ
// checks if the last two words on the stack are equal
equal := 0
if machine.Pop() == machine.Pop() { equal = 1 }
machine.Push(equal)
case 0x9:
// GT
// checks if the last word on the stack is greater than
// the second to last word on the stack
greater := 0
if machine.Pop() > machine.Pop() { greater = 1 }
machine.Push(greater)
case 0xa:
// LT
// checks if the last word on the stack is less than the
// second to last word on the stack
less := 0
if machine.Pop() > machine.Pop() { less = 1 }
machine.Push(less)
case 0xb:
// NEQ
// checks if the last two words on the stack are not
// equal
notEqual := 0
if machine.Pop() != machine.Pop() { notEqual = 1 }
machine.Push(notEqual)
case 0xc:
case 0xd:
case 0xe: