From 589657e31b1014a88f4805e6da4d3e5790cf3eeb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 28 Aug 2022 17:03:15 -0400 Subject: [PATCH] Implemented comparison instructions --- creature.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/creature.go b/creature.go index 9f54810..befc13e 100644 --- a/creature.go +++ b/creature.go @@ -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: