Fix index check

master
Jonas Franz 4 years ago
parent 34645bfe14
commit 4ab4187c44
Signed by: JonasFranzDEV
GPG Key ID: 7293A220B7C38080
  1. 13
      hal/instructions.go

@ -105,10 +105,6 @@ var InstructionIn = &Instruction{
var InstructionLoad = &Instruction{
Name: "LOAD",
ExecuteWithOperand: func(module *Module, operand float64) error {
index := int(operand)
if len(module.register) <= index {
return fmt.Errorf("index %d exceeds register size of %d", index, len(module.IO))
}
module.accumulator = module.mmu.Read(Address(operand))
return nil
},
@ -125,10 +121,6 @@ var InstructionLoadNum = &Instruction{
var InstructionStore = &Instruction{
Name: "STORE",
ExecuteWithOperand: func(module *Module, operand float64) error {
index := int(operand)
if len(module.register) <= index {
return fmt.Errorf("index %d exceeds register size of %d", index, len(module.IO))
}
module.mmu.Write(Address(operand), module.accumulator)
return nil
},
@ -204,11 +196,6 @@ func newMathInstruction(name string, operation func(accumulator, register float6
return &Instruction{
Name: name,
ExecuteWithOperand: func(module *Module, operand float64) error {
index := int(operand)
if len(module.register) <= index {
return fmt.Errorf("index %d does not exist in register", index)
}
param := module.mmu.Read(Address(index))
module.accumulator = operation(module.accumulator, param)
return nil

Loading…
Cancel
Save