Documentation ¶
Overview ¶
Package mix simulates the MIX 1009 computer as described in Donald Knuth's "The Art of Computer Programming" (third edition).
Index ¶
- Constants
- Variables
- func CompareFloatWord(u, v Word) int
- func ConvertToUTF8(w []Word) string
- func Disassemble(w Word) string
- func IsChar(r rune) bool
- func IsDigit(r rune) bool
- func IsLetter(r rune) bool
- func IsPunchable(s string) (rune, bool)
- func IsSpace(r rune) bool
- func OverPunch(digit rune) rune
- func RotateBitsLeft(high, low *Word, count int)
- func RotateBitsRight(high, low *Word, count int)
- func ShiftBitsLeft(high, low *Word, count int)
- func ShiftBitsRight(high, low *Word, count int)
- func Spec(left, right int) int
- type Binding
- type CardPunch
- type CardReader
- type Computer
- type Disc
- type Drum
- type PaperTape
- type Peripheral
- type Printer
- type Tape
- type Teletype
- type Word
- func AddFloatWord(u, v Word) (result Word, overflow bool)
- func AddWord(w Word, v int) (result Word, overflow bool)
- func AndWord(w Word, v int) Word
- func ConvertToMIX(s string) ([]Word, error)
- func DivFloatWord(u, v Word) (result Word, overflow bool)
- func DivWord(high, low Word, v int) (quot, rem Word, overflow bool)
- func FixedToFloat(w Word) (result Word, overflow bool)
- func FloatToFixed(w Word) (result Word, overflow bool)
- func MulFloatWord(u, v Word) (result Word, overflow bool)
- func MulWord(w Word, v int) (high, low Word)
- func NewWord(val int) Word
- func OrWord(w Word, v int) Word
- func SubFloatWord(u, v Word) (result Word, overflow bool)
- func SubWord(w Word, v int) (result Word, overflow bool)
- func XorWord(w Word, v int) Word
- func (w Word) Field(f int) Word
- func (w Word) GoString() string
- func (w Word) Int() int
- func (w Word) Negate() Word
- func (w *Word) PackFloat(e, f int)
- func (w *Word) PackOp(aa Word, i, f, c int)
- func (w *Word) SetField(f int, val Word)
- func (w Word) Sign() int
- func (w Word) String() string
- func (w Word) UnpackFloat() (e, f int)
- func (w Word) UnpackOp() (aa Word, i, f, c int)
Constants ¶
const ( // The I/O devices supported by the MIX 1009 computer. Tape0Unit = iota Tape1Unit Tape2Unit Tape3Unit Tape4Unit Tape5Unit Tape6Unit Tape7Unit Drum8Unit Drum9Unit Drum10Unit Drum11Unit Disc12Unit Disc13Unit Disc14Unit Disc15Unit CardReaderUnit CardPunchUnit PrinterUnit TeletypeUnit PaperTapeUnit DeviceCount )
const ( // The registers of the MIX 1009 CPU. A = iota I1 I2 I3 I4 I5 I6 X J // Less, Equal and Greater are the possible values taken by the // computer's comparison indicator. Less = -1 Equal = 0 Greater = 1 // MemorySize is the number of memory cells in a regular MIX computer. MemorySize = 4000 )
const ( // The opcodes for the MIX 1009 computer (see Table 1, Section 1.3.1) NOP = iota ADD // FADD SUB // FSUB MUL // FMUL DIV // FDIV NUM // CHAR, HLT, AND, OR, XOR, FLOT, FIX, INT SLA // SRA, SLAX, SRAX, SLC, SRC, SLB, SRB MOVE LDA LD1 LD2 LD3 LD4 LD5 LD6 LDX LDAN LD1N LD2N LD3N LD4N LD5N LD6N LDXN STA ST1 ST2 ST3 ST4 ST5 ST6 STX STJ STZ JBUS IOC IN OUT JRED JMP // JSJ, JOV, JNOV, JL, JE, JG, JGE, JNE, JLE JA // JAN, JAZ, JAP, JANN, JANZ, JANP, JAE, JEO J1 // J1N, J1Z, J1P, J1NN, J1NZ, J1NP J2 // J2N, J2Z, J2P, J2NN, J2NZ, J2NP J3 // J3N, J3Z, J3P, J3NN, J3NZ, J3NP J4 // J4N, J4Z, J4P, J4NN, J4NZ, J4NP J5 // J5N, J5Z, J5P, J5NN, J5NZ, J5NP J6 // J6N, J6Z, J6P, J6NN, J6NZ, J6NP JX // JXN, JXZ, JXP, JXNN, JXNZ, JXNP, JXE, JXO INCA // DECA, ENTA, ENNA INC1 // DEC1, ENT1, ENN1 INC2 // DEC2, ENT2, ENN2 INC3 // DEC3, ENT3, ENN3 INC4 // DEC4, ENT4, ENN4 INC5 // DEC5, ENT5, ENN5 INC6 // DEC6, ENT6, ENN6 INCX // DECX, ENTX, ENNX CMPA // FCMP CMP1 CMP2 CMP3 CMP4 CMP5 CMP6 CMPX )
const ( // The largest and smallest values that are representable // by a MIX word. MaxWord = 1<<30 - 1 MinWord = -MaxWord // The largest and smallest values that are representable // by the MIX index registers and the jump register. MaxIndex = 1<<12 - 1 MinIndex = -MaxIndex )
Variables ¶
var ( DefaultBinding = &defBind ErrInvalidUnit = errors.New("mix: invalid I/O unit") ErrNoDevice = errors.New("mix: no I/O device") )
var ( ErrInvalidAddress = errors.New("mix: invalid address") ErrInvalidIndex = errors.New("mix: invalid index") ErrInvalidOp = errors.New("mix: invalid operation") ErrContentsInterlock = errors.New("mix: contents interlock") )
var ( ErrHalted = errors.New("mix: halted") ErrNoInterrupts = errors.New("mix: interrupts are disabled") )
var ErrFormat = errors.New("mix: format error")
var ErrInvalidBlock = errors.New("mix: invalid block")
var ErrInvalidChar = errors.New("mix: invalid character")
var ErrInvalidCommand = errors.New("mix: invalid I/O command")
ErrInvalidCommand is returned when an I/O device is asked to do something it does not support, eg. requesting input from the printer.
var ErrInvalidSpec = errors.New("mix: invalid field specification")
var ErrNotImplemented = errors.New("mix: not implemented")
Functions ¶
func CompareFloatWord ¶
func ConvertToUTF8 ¶
func Disassemble ¶
func IsPunchable ¶
func RotateBitsLeft ¶
RotateBitsLeft rotates a double MIX word left by the given number of bits.
func RotateBitsRight ¶
RotateBitsRight rotates a double MIX word right by the given number of bits.
func ShiftBitsLeft ¶
ShiftBitsLeft shifts a double MIX word left by the given number of bits.
func ShiftBitsRight ¶
ShiftBitsRight shifts a double MIX word right by the given number of bits.
Types ¶
type Binding ¶
type Binding [DeviceCount]interface{}
type CardPunch ¶
type CardPunch struct {
// contains filtered or unexported fields
}
func NewCardPunch ¶
func NewCardPunch(wc io.WriteCloser) (*CardPunch, error)
type CardReader ¶
type CardReader struct {
// contains filtered or unexported fields
}
func NewCardReader ¶
func NewCardReader(r io.Reader) (*CardReader, error)
func (*CardReader) BlockSize ¶
func (*CardReader) BlockSize() int
func (*CardReader) Close ¶
func (r *CardReader) Close() error
func (*CardReader) Name ¶
func (*CardReader) Name() string
type Computer ¶
type Computer struct { Overflow bool Comparison int Elapsed, Idle int64 Reg [10]Word Contents []Word Devices []Peripheral Tracer io.WriteCloser Trigger int Interrupts bool BootFrom int // contains filtered or unexported fields }
func NewComputer ¶
func NewComputer() *Computer
type Disc ¶
type Disc struct {
// contains filtered or unexported fields
}
type Drum ¶
type Drum struct {
// contains filtered or unexported fields
}
type PaperTape ¶
type PaperTape struct {
// contains filtered or unexported fields
}
func NewPaperTape ¶
type Peripheral ¶
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
func NewPrinter ¶
func NewPrinter(wc io.WriteCloser) (*Printer, error)
type Teletype ¶
type Teletype struct {
// contains filtered or unexported fields
}
func NewTeletype ¶
func NewTeletype(rwc io.ReadWriteCloser) (*Teletype, error)
type Word ¶
type Word int32
Word represents a MIX machine word, which consists of five 6-bit bytes and a sign bit.
func AddFloatWord ¶
AddFloatWord returns the sum of two floating point MIX words, and whether overflow occurred. See Section 4.2.1.
func AddWord ¶
AddWord adds an integer to a MIX word, returning the result as a MIX word, and whether overflow occurred. See Section 1.3.1.
func AndWord ¶
AndWord returns the bitwise-AND of a MIX word and an integer (the sign of the MIX word is preserved)
func ConvertToMIX ¶
func DivFloatWord ¶
func DivWord ¶
DivWord divides a double-precision MIX word by an integer, returning the quotient and remainder as MIX words, and whether overflow or division by zero occurred. See Section 1.3.1.
func FixedToFloat ¶
func FloatToFixed ¶
func MulFloatWord ¶
func MulWord ¶
MulWord multiplies a MIX word by an integer, returning the product as two (double-precision) MIX words. See Section 1.3.1.
func NewWord ¶
NewWord returns a MIX word with the given integer value. It panics if the value is out of range.
func OrWord ¶
OrWord returns the bitwise-OR of a MIX word and an integer (the sign of the MIX word is preserved)
func SubFloatWord ¶
func SubWord ¶
SubWord subtracts an integer from a MIX word, returning the result as a MIX word, and whether overflow occurred. See Section 1.3.1.
func XorWord ¶
XorWord returns the bitwise-XOR of a MIX word and an integer (the sign of the MIX word is preserved)
func (*Word) PackFloat ¶
PackFloat composes a MIX word from a floating point number's exponent and fraction.
func (*Word) PackOp ¶
PackOp composes a MIX word from a MIX instruction's address, index, field and opcode.
func (Word) String ¶
String returns a representation of the value of a MIX word as a decimal number. Note that a MIX word can have a value of negative zero.
func (Word) UnpackFloat ¶
UnpackFloat extracts the exponent and fraction of a floating point number in a MIX word.
Source Files ¶
- arith.go
- bind.go
- charset.go
- compare.go
- computer.go
- cycle.go
- disassemble.go
- disc.go
- drum.go
- field.go
- float.go
- go.go
- inc.go
- interrupt.go
- io.go
- jump.go
- load.go
- microcode.go
- move.go
- num.go
- opcodes.go
- paper.go
- peripheral.go
- printer.go
- priority.go
- punch.go
- reader.go
- save.go
- shift.go
- tape.go
- teletype.go
- trace.go
- word.go