From 574c217c0df29327bb6f96f551ce74278ba7fd5f Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 18 May 2020 21:22:51 +0200 Subject: [PATCH] Fix add --- hal/instructions.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hal/instructions.go b/hal/instructions.go index 543f0fd..710a5db 100644 --- a/hal/instructions.go +++ b/hal/instructions.go @@ -160,11 +160,13 @@ var InstructionJump = newJumpInstruction("JUMP", func(accumulator float64) bool var InstructionAdd = &Instruction{ Name: "ADD", ExecuteWithOperand: func(module *Module, operand float64) error { - index := int64(operand) - if _, ok := module.programStorage[index]; !ok { + index := int(operand) + if len(module.register) <= index { return fmt.Errorf("index %d does not exist in program storage", index) } + module.accumulator += module.register[index] + return nil }, }