You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/hal/module.go

33 lines
770 B

package hal
import "fmt"
type Program []*ProgrammedInstruction
type Module struct {
Accumulator int64
ProgramStorage Program
Register []int64
}
func (h *Module) ProgramCounter() int64 {
return h.Register[0]
}
func (h *Module) Step() error {
instruction := h.ProgramStorage[h.ProgramCounter()]
if instruction == nil {
return fmt.Errorf("instruction not found for program counter = %d", h.ProgramCounter())
}
return instruction.Execute(h)
}
func NewHALModule(program Program, registerSize uint64) (*Module, error) {
if registerSize <= 10 {
return nil, fmt.Errorf("register size must be greater then 10 [ registerSize = %d ]", registerSize)
}
return &Module{
ProgramStorage: program,
Register: make([]int64, registerSize),
}, nil
}