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 }, }