diff --git a/hal/instructions.go b/hal/instructions.go index ceed661..3e43777 100644 --- a/hal/instructions.go +++ b/hal/instructions.go @@ -58,8 +58,8 @@ var InstructionStop = &Instruction{ var InstructionOut = &Instruction{ Name: "OUT", - Execute: func(module *Module) { - // TODO implement + ExecuteWithOperand: func(module *Module, operand float64) { + module.IO[int64(operand)] = module.accumulator }, } diff --git a/hal/module.go b/hal/module.go index a218b1e..04b1db8 100644 --- a/hal/module.go +++ b/hal/module.go @@ -7,23 +7,23 @@ const maxInstructions = 1000 type Program map[int64]*ProgrammedInstruction type Module struct { - Accumulator float64 - ProgramStorage Program - Register []float64 + accumulator float64 + programStorage Program + register []float64 IO []float64 isStopped bool } func (h *Module) ProgramCounter() int64 { - return int64(h.Register[0]) + return int64(h.register[0]) } func (h *Module) increaseProgramCounter() { - h.Register[0]++ + h.register[0]++ } func (h *Module) Step() { - instruction := h.ProgramStorage[h.ProgramCounter()] + instruction := h.programStorage[h.ProgramCounter()] h.increaseProgramCounter() if instruction == nil { return @@ -46,8 +46,8 @@ func NewHALModule(program Program, registerSize uint64, ioSize uint64) (*Module, return nil, fmt.Errorf("register size must be greater then 10 [ registerSize = %d ]", registerSize) } return &Module{ - ProgramStorage: program, - Register: make([]float64, registerSize), + programStorage: program, + register: make([]float64, registerSize), IO: make([]float64, ioSize), }, nil }