Documentation
¶
Overview ¶
Package emu implements an emulator for the RISC dialect described in risc/op.
Index ¶
- Constants
- Variables
- type PC
- type System
- func (sys *System) Add(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)
- func (sys *System) AddFloat(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)
- func (sys *System) And(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)
- func (sys *System) CmpBranch(cmp op.Reg, addr op.Addr) (err error)
- func (sys *System) Exec(inst interface{}) (err error)
- func (sys *System) FetchInst() (buf uint16, err error)
- func (sys *System) Halt() (err error)
- func (sys *System) LoadMem(dst op.Reg, src op.Addr) (err error)
- func (sys *System) LoadVal(dst op.Reg, src op.Val) (err error)
- func (sys *System) Move(dst op.Reg, src op.Reg) (err error)
- func (sys *System) Nop()
- func (sys *System) Or(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)
- func (sys *System) Reset()
- func (sys *System) Ror(reg op.Reg, x op.Val) (err error)
- func (sys *System) Run() (err error)
- func (sys *System) Start()
- func (sys *System) Step() (err error)
- func (sys *System) Store(dst op.Addr, src op.Reg) (err error)
- func (sys *System) String() string
- func (sys *System) Xor(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)
Constants ¶
const (
// MemSize specifies the size of the memory in bytes.
MemSize = 256
)
Information about the emulator system.
Variables ¶
var ErrHalted = errors.New("emu: system is halted")
ErrHalted is returned when trying to execute an instruction while the system is halted.
Functions ¶
This section is empty.
Types ¶
type PC ¶
type PC uint8
PC is a system's program counter. It holds the address of the next instruction to be executed.
type System ¶
type System struct { // Program counter. PC PC // Registers r0 through r15. Regs [op.RegCount]uint8 // Memory. Mem [MemSize]uint8 // contains filtered or unexported fields }
A System capable of running the RISC dialect described in risc/op.
func New ¶
New allocates and returns a new system, initiating the memory with the contents read from r. The remaining memory, the program counter and all registers are set to 0.
Remember to call sys.Start before executing instructions.
func (*System) Add ¶
Add adds the contents of the src1 and src2 registers, as though they represented values in two's complement notation, and stores the result in the dst register.
func (*System) AddFloat ¶
AddFloat adds the contents of the src1 and src2 registers, as though they represented values in floating-point notation, and stores the result in the dst register.
func (*System) And ¶
And performs a bitwise AND operation on the bit patterns in the src1 and src2 registers and stores the result in the dst register.
func (*System) CmpBranch ¶
CmpBranch jumps to the instruction located at the addr memory address if the contents of the cmp registers is equal to the contents of the 0 register. Otherwise, continue with the normal sequence of execution.
This jump is "unconditional" when cmp == 0.
func (*System) FetchInst ¶
FetchInst fetches the next instruction and increments the program counter.
func (*System) LoadMem ¶
LoadMem loads the contents of the src memory address into the dst register.
func (*System) Or ¶
Or performs a bitwise OR operation on the bit patterns in the src1 and src2 registers and stores the result in the dst register.
func (*System) Reset ¶
func (sys *System) Reset()
Reset resets the system by clearing the memory and all registers. It will also halt the system.
Remember to call sys.Start before executing instructions.
func (*System) Ror ¶
Ror rotate the bit pattern in the reg register x bits to the right. Each time a bit is rotated out of the low-order end it is placed at the high-order end.
func (*System) Run ¶
Run starts the system and executes instructions until an error or ErrHalted. A successful call to Run return err == nil, not err == ErrHalted. Because Run is defined to execute instructions until ErrHalted, it does not treat ErrHalted as an error to report.
func (*System) Start ¶
func (sys *System) Start()
Start starts the system, so it can execute instructions.