vm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FLGPOS for 'Positive' result
	FLGPOS uint16 = 1 << 0
	// FLGZRO for 'Zero' result
	FLGZRO uint16 = 1 << 1
	// FLGNEG for 'Negative' result
	FLGNEG uint16 = 1 << 2
)
View Source
const (
	// BR 0  ~> branch
	BR uint16 = iota
	// ADD 1  ~> add
	ADD uint16 = iota
	// LD 2  ~> load
	LD uint16 = iota
	// ST 3  ~> store
	ST uint16 = iota
	// JSR 4  ~> jump register
	JSR uint16 = iota
	// AND 5  ~> bitwise and
	AND uint16 = iota
	// LDR 6  ~> load register
	LDR uint16 = iota
	// STR 7  ~> store register
	STR uint16 = iota
	// RTI 8  ~> unused
	RTI uint16 = iota
	// NOT 9  ~> bitwise not
	NOT uint16 = iota
	// LDI 10 ~> load indirect
	LDI uint16 = iota
	// STI 11 ~> store indirect
	STI uint16 = iota
	// JMP 12 ~> jump
	JMP uint16 = iota
	// RES 13 ~> reserved (unused)
	RES uint16 = iota
	// LEA 14 ~> load effective address
	LEA uint16 = iota
	// TRAP 15 ~> execute trap
	TRAP uint16 = iota
)

Operation codes

View Source
const (
	// KBSR is a keyboard status
	KBSR uint16 = 0xFE00
	// KBDR is a keyboard data
	KBDR uint16 = 0xFE02
)
View Source
const (
	// GETC to get character from keyboard, not echoed onto the terminal
	GETC uint16 = 0x20
	// OUT to output a character
	OUT uint16 = 0x21
	// PUTS to output a word string
	PUTS uint16 = 0x22
	// IN to get character from keyboard, echoed onto the terminal
	IN uint16 = 0x23
	// PUTSP to output a byte string
	PUTSP uint16 = 0x24
	// HALT to halt the program
	HALT uint16 = 0x25
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CPU

type CPU struct {
	Memory     [math.MaxUint16 + 1]uint16 // 65536 locations (128kb)
	KeysBuffer []rune                     // Key Buffer
	IsRunning  bool                       // Run state

	// 10 total registers.
	Registers [8]uint16 // general purpose
	PC        uint16    // program counter
	COND      uint16    // condition flags
}

CPU is a LC-3 CPU emulator.

func NewCPU

func NewCPU() *CPU

NewCPU initialize a new LC3 CPU

func (*CPU) KBinputLoop

func (cpu *CPU) KBinputLoop()

KBinputLoop is a keyboard input processing loop

func (*CPU) LoadProgramImage

func (cpu *CPU) LoadProgramImage(path string) error

LoadProgramImage from the given path

func (*CPU) Run

func (cpu *CPU) Run() error

Run executes the loaded program

func (*CPU) Stop

func (cpu *CPU) Stop()

Stop emulates the termination signal

Jump to

Keyboard shortcuts

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