emu

package
v0.0.0-...-ec3c368 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Overview

Package emu implements an emulator for the RISC dialect described in risc/op.

Index

Constants

View Source
const (
	// MemSize specifies the size of the memory in bytes.
	MemSize = 256
)

Information about the emulator system.

Variables

View Source
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.

func (*PC) Inc

func (pc *PC) Inc(n int) (err error)

Inc increases the program counter, taking special precaution to limit integer overflows and underflows. To decrease the program counter provide a negative n value.

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

func New(r io.Reader) (sys *System, err error)

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

func (sys *System) Add(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)

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

func (sys *System) AddFloat(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)

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

func (sys *System) And(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)

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

func (sys *System) CmpBranch(cmp op.Reg, addr op.Addr) (err error)

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) Exec

func (sys *System) Exec(inst interface{}) (err error)

Exec executes the provided instruction.

func (*System) FetchInst

func (sys *System) FetchInst() (buf uint16, err error)

FetchInst fetches the next instruction and increments the program counter.

func (*System) Halt

func (sys *System) Halt() (err error)

Halt halts execution of the system.

func (*System) LoadMem

func (sys *System) LoadMem(dst op.Reg, src op.Addr) (err error)

LoadMem loads the contents of the src memory address into the dst register.

func (*System) LoadVal

func (sys *System) LoadVal(dst op.Reg, src op.Val) (err error)

LoadVal loads the src immediate value into the dst register.

func (*System) Move

func (sys *System) Move(dst op.Reg, src op.Reg) (err error)

Move moves the contents of the src register into the dst register.

func (*System) Nop

func (sys *System) Nop()

Nop performs no operation.

func (*System) Or

func (sys *System) Or(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)

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

func (sys *System) Ror(reg op.Reg, x op.Val) (err error)

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

func (sys *System) Run() (err error)

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.

func (*System) Step

func (sys *System) Step() (err error)

Step decodes and executes one instruction.

func (*System) Store

func (sys *System) Store(dst op.Addr, src op.Reg) (err error)

Store stores the contents of the src register into the dst memory address.

func (*System) String

func (sys *System) String() string

String returns pretty-printed memory and register information about the system.

func (*System) Xor

func (sys *System) Xor(dst op.Reg, src1 op.Reg, src2 op.Reg) (err error)

Xor performs a bitwise XOR operation on the bit patterns in the src1 and src2 registers and stores the result in the dst register.

Directories

Path Synopsis
cmd
emu
Command emu emulates a system capable of running the RISC dialect described in risc/op.
Command emu emulates a system capable of running the RISC dialect described in risc/op.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL