vm

package
v0.0.0-...-8cd90ef Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	R_R0 uint16 = iota
	R_R1
	R_R2
	R_R3
	R_R4
	R_R5
	R_R6
	R_R7
	R_PC // program counter
	R_COND
	R_COUNT
)

Registers

View Source
const (
	OP_BR   uint16 = iota // branch
	OP_ADD                // add
	OP_LD                 // load
	OP_ST                 // store
	OP_JSR                // jump register
	OP_AND                // bitwise and
	OP_LDR                // load register
	OP_STR                // store register
	OP_RTI                // unused
	OP_NOT                // bitwise not
	OP_LDI                // load indirect
	OP_STI                // store indirect
	OP_JMP                // jump
	OP_RES                // reserved (unused)
	OP_LEA                // load effective address
	OP_TRAP               // execute trap
)

Opcodes

View Source
const (
	FL_POS uint16 = 1 << 0 // Positive
	FL_ZRO uint16 = 1 << 1 // Zero
	FL_NEG uint16 = 1 << 2 // Negative
)

Condition Flags

View Source
const (
	TRAP_GETC  = 0x20 // get character from keyboard, not echoed onto the terminal
	TRAP_OUT   = 0x21 // output a character
	TRAP_PUTS  = 0x22 // output a word string
	TRAP_IN    = 0x23 // get character from keyboard, echoed onto the terminal
	TRAP_PUTSP = 0x24 // output a byte string
	TRAP_HALT  = 0x25 // halt the program
)
View Source
const (
	MR_KBSR uint16 = 0xfe00 // keyboard status
	MR_KBDR uint16 = 0xfe02 // keyboard data
)
View Source
const MaxMemorySize uint16 = 65535

MaxMemorySize maximum RAM size.

View Source
const PC_START uint16 = 0x3000

Variables

This section is empty.

Functions

func CheckKeyPressed

func CheckKeyPressed() bool

CheckKeyPressed checks if a key was pressed.

func GetCharFromStdin

func GetCharFromStdin() uint16

GetCharFromStdin get one char from standard input.

Types

type CheckKey

type CheckKey func() bool

CheckKey checks is keyboard key has been pressed.

type GetChar

type GetChar func() uint16

GetChar reads single character from input device.

type LC3CPU

type LC3CPU struct {
	RAM *LC3RAM

	StartPosition uint16
	// contains filtered or unexported fields
}

LC3CPU describes CPU abstraction.

func NewCPU

func NewCPU(ram *LC3RAM, output io.Writer) *LC3CPU

NewCPU creates new LC-3 CPU instance.

func (*LC3CPU) Reset

func (v *LC3CPU) Reset()

Reset resets CPU to initial state.

func (*LC3CPU) Run

func (v *LC3CPU) Run()

Run runs CPU.

type LC3RAM

type LC3RAM struct {
	CheckKey
	GetChar
	Storage [MaxMemorySize]uint16
}

LC3RAM describes memory abstraction for LC3CPU.

func (*LC3RAM) Load

func (m *LC3RAM) Load(path string)

Load loads program into the memory.

func (*LC3RAM) Read

func (m *LC3RAM) Read(address uint16) uint16

Read reads a value from memory.

func (*LC3RAM) Write

func (m *LC3RAM) Write(address, val uint16)

Write writes value to memory on specified address.

Jump to

Keyboard shortcuts

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