Implement out instruction

master
Jonas Franz 5 years ago
parent c94a6e02d8
commit 743ec2c0b5
Signed by: JonasFranzDEV
GPG Key ID: 7293A220B7C38080
  1. 4
      hal/instructions.go
  2. 16
      hal/module.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
},
}

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

Loading…
Cancel
Save