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{ var InstructionOut = &Instruction{
Name: "OUT", Name: "OUT",
Execute: func(module *Module) { ExecuteWithOperand: func(module *Module, operand float64) {
// TODO implement module.IO[int64(operand)] = module.accumulator
}, },
} }

@ -7,23 +7,23 @@ const maxInstructions = 1000
type Program map[int64]*ProgrammedInstruction type Program map[int64]*ProgrammedInstruction
type Module struct { type Module struct {
Accumulator float64 accumulator float64
ProgramStorage Program programStorage Program
Register []float64 register []float64
IO []float64 IO []float64
isStopped bool isStopped bool
} }
func (h *Module) ProgramCounter() int64 { func (h *Module) ProgramCounter() int64 {
return int64(h.Register[0]) return int64(h.register[0])
} }
func (h *Module) increaseProgramCounter() { func (h *Module) increaseProgramCounter() {
h.Register[0]++ h.register[0]++
} }
func (h *Module) Step() { func (h *Module) Step() {
instruction := h.ProgramStorage[h.ProgramCounter()] instruction := h.programStorage[h.ProgramCounter()]
h.increaseProgramCounter() h.increaseProgramCounter()
if instruction == nil { if instruction == nil {
return 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 nil, fmt.Errorf("register size must be greater then 10 [ registerSize = %d ]", registerSize)
} }
return &Module{ return &Module{
ProgramStorage: program, programStorage: program,
Register: make([]float64, registerSize), register: make([]float64, registerSize),
IO: make([]float64, ioSize), IO: make([]float64, ioSize),
}, nil }, nil
} }

Loading…
Cancel
Save