From c3ca9892620ad50261b4a624c89969236754ffeb Mon Sep 17 00:00:00 2001 From: kolaente <k@knt.li> Date: Mon, 18 May 2020 21:16:03 +0200 Subject: [PATCH] Fix addnum --- hal/instructions.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hal/instructions.go b/hal/instructions.go index 6f7e669..8d7a3e1 100644 --- a/hal/instructions.go +++ b/hal/instructions.go @@ -135,9 +135,22 @@ var InstructionJumpNeg = &Instruction{ }, } -var InstructionAddnum = &Instruction{ +var InstructionAdd = &Instruction{ + Name: "ADD", + ExecuteWithOperand: func(module *Module, operand float64) error { + index := int64(operand) + if _, ok := module.programStorage[index]; !ok { + return fmt.Errorf("index %d does not exist in program storage", index) + } + + return nil + }, +} + +var InstructionAddNum = &Instruction{ Name: "ADDNUM", - ExecuteWithOperand: func(module *Module, operand float64) { + ExecuteWithOperand: func(module *Module, operand float64) error { module.accumulator = module.accumulator + operand + return nil }, }