Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertInstructionAndAddrListToHexStrList(data []*InstructionAndAddr) []string
- func ConvertIntToTwoByte(addr int) (higherByte, lowerByte byte)
- func ConvertTwoByteToInt(higherByte, lowerByte byte) int
- func DirectWrite(addr int, w *Word)
- func Execute(options ...SimulateOption) error
- func ExecuteOneInstruction() error
- func GetLeftInstructionFromMBR() (opcode byte, addr int)
- func GetRightInstructionFromMBR() (opcode byte, addr int)
- func Init()
- func InitInstructionSet()
- func PrintStatus()
- func SPrintStatus() string
- func SetInstructions(data []*InstructionAndAddr, startAddr int)
- func TakeInstructionFromLeftM()
- func TakeInstructionFromRightM()
- func TakeNextInstruction()
- type AddressRegister
- type ExecuteParam
- type InstructionAddAbsM
- type InstructionAddM
- type InstructionAndAddr
- type InstructionBufferRegister
- type InstructionConditionalJumpMLeft
- type InstructionConditionalJumpMRight
- type InstructionDivideM
- type InstructionInterface
- type InstructionJumpMLeft
- type InstructionJumpMRight
- type InstructionLSH
- type InstructionLoadAbsM
- type InstructionLoadM
- type InstructionLoadMQ
- type InstructionLoadMToMQ
- type InstructionLoadNegativeAbsM
- type InstructionLoadNegativeM
- type InstructionMultiplyM
- type InstructionRSH
- type InstructionRegister
- type InstructionSet
- type InstructionStoreM
- type InstructionStoreMLeftAddr
- type InstructionStoreMRightAddr
- type InstructionSubAbsM
- type InstructionSubM
- type Memory
- type Register
- type SimulateOption
- type Word
- func (w *Word) Abs() *Word
- func (w *Word) Add(w2 *Word) *Word
- func (r *Word) Clear()
- func (w *Word) DeepCopy() *Word
- func (w *Word) Div(w2 *Word) (quotient, remainder *Word)
- func (r *Word) IsEmpty() bool
- func (r *Word) IsNegative() bool
- func (w *Word) IsValid() bool
- func (w *Word) LSH() *Word
- func (w *Word) Mul(w2 *Word) (higherWord, lowerWord *Word)
- func (w *Word) Opposite() *Word
- func (w *Word) RSH() *Word
- func (w *Word) Sub(w2 *Word) *Word
- func (w *Word) ToHexStr() string
- func (w *Word) ToInt64() int64
Constants ¶
View Source
const ( DefaultMaxSteps = 100000 DefaultHaultAt = -1 )
View Source
const ( // Data transfer // Transfer MQ to AC, MQ is multiply-quotient register OpcodeLoadMQ = 0b00001010 // Transfer M(X) to MQ OpcodeLoadMToMQ = 0b00001001 // Transfer AC to memory location x OpcodeStoreM = 0b00100001 // Transfer M(X) to the AC, AC is accumulator register OpcodeLoadM = 0b00000001 // Transfer -M(X) to AC OpcodeLoadNegativeM = 0b00000010 // Transfer |M(X)| to AC OpcodeLoadAbsM = 0b00000011 // Transfer -|M(X)| to AC OpcodeLoadNegativeAbsM = 0b00000100 // Unconditional branch // Take next instructionfrom left half of M(X) OpcodeJumpMLeft = 0b00001101 // Take next instructionfrom right half of M(X) OpcodeJumpMRight = 0b00001110 // Conditional branch // If the number in the AC is nonnegative take the next instruction from left half of M(X) OpcodeConditionalJumpMLeft = 0b00001111 // If the number in the AC is nonnegative take the next instruction from right half of M(X) OpcodeConditionalJumpMRight = 0b00010000 // Arithmetic // Add M(X) to AC, put the result in AC OpcodeAddM = 0b00000101 // Add |M(X)| to AC, put the result in AC OpcodeAddAbsM = 0b00000111 // Substract M(X) from AC, put the resul in AC OpcodeSubM = 0b00000110 // Substract |M(X)| from AC, put the resul in AC OpcodeSubAbsM = 0b00001000 // Multiply M(X) by MQ, put most significant bits of result in AC, put least significant bits in MQ OpcodeMultiplyM = 0b00001011 // Divide AC by M(X), put the quotient in MQ and the remainder in AC OpcodeDivideM = 0b00001100 // Multiply AC by 2, that is, shift left one bit position OpcodeLSH = 0b00010100 // Divide AC by 2, that is, shift right one position OpcodeRSH = 0b00010101 // Addresss modify // Replace left address field at M(X)[8:19] by 12 rightmost bits of AC OpcodeStoreMLeftAddr = 0b00010010 // Replace right address field at M(X)[28:39] by 12 rightmost bits of AC OpcodeStoreMRightAddr = 0b00010011 )
Variables ¶
View Source
var ( FlagIsNextInstructionInIBR bool FlagLeftInsturctionRequired bool // 下一个指令应该执行左边的指令吗 )
View Source
var ( // Accumulator register, 40 bit AC *Register // Multiply-quotient register, 40 bit MQ *Register // Memory buffer register, 40 bit MBR *Register // Memory address register, 12 bit MAR *AddressRegister // Program counter, 12 bit PC *AddressRegister // Instruction buffer register, 20bit IBR *InstructionBufferRegister // Instruction register, 8 bit IR *InstructionRegister )
Functions ¶
func ConvertInstructionAndAddrListToHexStrList ¶
func ConvertInstructionAndAddrListToHexStrList(data []*InstructionAndAddr) []string
将程序转化为16进制的格式
func ConvertIntToTwoByte ¶
func ConvertTwoByteToInt ¶
func InitInstructionSet ¶
func InitInstructionSet()
func SetInstructions ¶
func SetInstructions(data []*InstructionAndAddr, startAddr int)
将程序写入内存,用于初始化的环节。将指令按顺序从指定地址开始写入内存。
func TakeInstructionFromLeftM ¶
func TakeInstructionFromLeftM()
TakeInstructionFromLeftM takes next instruction from left half of M(x)
func TakeInstructionFromRightM ¶
func TakeInstructionFromRightM()
TakeInstructionFromRightM takes next instruction from right half of M(x)
func TakeNextInstruction ¶
func TakeNextInstruction()
TakeNextInstruction take the next instruction into IR
Types ¶
type AddressRegister ¶
type AddressRegister struct {
// contains filtered or unexported fields
}
func NewAddressRegister ¶
func NewAddressRegister() *AddressRegister
func (*AddressRegister) GetAddr ¶
func (r *AddressRegister) GetAddr() int
func (*AddressRegister) Increase ¶
func (r *AddressRegister) Increase()
func (*AddressRegister) SetAddr ¶
func (r *AddressRegister) SetAddr(addr int)
type ExecuteParam ¶
type ExecuteParam struct {
// contains filtered or unexported fields
}
type InstructionAddAbsM ¶
type InstructionAddAbsM struct{}
ADD |M(X)|
func (*InstructionAddAbsM) Run ¶
func (instruction *InstructionAddAbsM) Run()
type InstructionAddM ¶
type InstructionAddM struct{}
ADD M(X)
func (*InstructionAddM) Run ¶
func (instruction *InstructionAddM) Run()
type InstructionAndAddr ¶
type InstructionBufferRegister ¶
type InstructionBufferRegister struct {
// contains filtered or unexported fields
}
func NewInstructionBufferRegister ¶
func NewInstructionBufferRegister() *InstructionBufferRegister
func (*InstructionBufferRegister) Clear ¶
func (r *InstructionBufferRegister) Clear()
func (*InstructionBufferRegister) IsEmpty ¶
func (r *InstructionBufferRegister) IsEmpty() bool
func (*InstructionBufferRegister) Read ¶
func (r *InstructionBufferRegister) Read() (code byte, addr int)
func (*InstructionBufferRegister) Write ¶
func (r *InstructionBufferRegister) Write(code byte, addr int)
type InstructionConditionalJumpMLeft ¶
type InstructionConditionalJumpMLeft struct{}
JUMP +M(X,0:19)
func (*InstructionConditionalJumpMLeft) Run ¶
func (instruction *InstructionConditionalJumpMLeft) Run()
type InstructionConditionalJumpMRight ¶
type InstructionConditionalJumpMRight struct{}
JUMP +M(X,20:39)
func (*InstructionConditionalJumpMRight) Run ¶
func (instruction *InstructionConditionalJumpMRight) Run()
type InstructionDivideM ¶
type InstructionDivideM struct{}
DIV M(X)
func (*InstructionDivideM) Run ¶
func (instruction *InstructionDivideM) Run()
type InstructionInterface ¶
type InstructionInterface interface {
Run()
}
type InstructionJumpMLeft ¶
type InstructionJumpMLeft struct{}
JUMP M(X,0:19)
func (*InstructionJumpMLeft) Run ¶
func (instruction *InstructionJumpMLeft) Run()
type InstructionJumpMRight ¶
type InstructionJumpMRight struct{}
JUMP M(X,20:39)
func (*InstructionJumpMRight) Run ¶
func (instruction *InstructionJumpMRight) Run()
type InstructionLSH ¶
type InstructionLSH struct{}
LSH
func (*InstructionLSH) Run ¶
func (instruction *InstructionLSH) Run()
type InstructionLoadAbsM ¶
type InstructionLoadAbsM struct{}
func (*InstructionLoadAbsM) Run ¶
func (instruction *InstructionLoadAbsM) Run()
type InstructionLoadM ¶
type InstructionLoadM struct{}
func (*InstructionLoadM) Run ¶
func (instruction *InstructionLoadM) Run()
type InstructionLoadMQ ¶
type InstructionLoadMQ struct{}
LOAD MQ
func (*InstructionLoadMQ) Run ¶
func (instruction *InstructionLoadMQ) Run()
type InstructionLoadMToMQ ¶
type InstructionLoadMToMQ struct{}
LOAD MQ,M(X)
func (*InstructionLoadMToMQ) Run ¶
func (instruction *InstructionLoadMToMQ) Run()
type InstructionLoadNegativeAbsM ¶
type InstructionLoadNegativeAbsM struct{}
func (*InstructionLoadNegativeAbsM) Run ¶
func (instruction *InstructionLoadNegativeAbsM) Run()
type InstructionLoadNegativeM ¶
type InstructionLoadNegativeM struct{}
func (*InstructionLoadNegativeM) Run ¶
func (instruction *InstructionLoadNegativeM) Run()
type InstructionMultiplyM ¶
type InstructionMultiplyM struct{}
MUL M(X)
func (*InstructionMultiplyM) Run ¶
func (instruction *InstructionMultiplyM) Run()
type InstructionRSH ¶
type InstructionRSH struct{}
RSH
func (*InstructionRSH) Run ¶
func (instruction *InstructionRSH) Run()
type InstructionRegister ¶
type InstructionRegister struct {
// contains filtered or unexported fields
}
func NewInstructionRegister ¶
func NewInstructionRegister() *InstructionRegister
func (*InstructionRegister) Read ¶
func (r *InstructionRegister) Read() byte
func (*InstructionRegister) Write ¶
func (r *InstructionRegister) Write(code byte)
type InstructionSet ¶
type InstructionSet struct {
// contains filtered or unexported fields
}
func (*InstructionSet) GetInstruction ¶
func (is *InstructionSet) GetInstruction(code byte) (InstructionInterface, error)
type InstructionStoreM ¶
type InstructionStoreM struct{}
func (*InstructionStoreM) Run ¶
func (instruction *InstructionStoreM) Run()
type InstructionStoreMLeftAddr ¶
type InstructionStoreMLeftAddr struct{}
STORE M(X,8:19)
func (*InstructionStoreMLeftAddr) Run ¶
func (instruction *InstructionStoreMLeftAddr) Run()
type InstructionStoreMRightAddr ¶
type InstructionStoreMRightAddr struct{}
STORE M(X,28:39)
func (*InstructionStoreMRightAddr) Run ¶
func (instruction *InstructionStoreMRightAddr) Run()
type InstructionSubAbsM ¶
type InstructionSubAbsM struct{}
SUB |M(X)|
func (*InstructionSubAbsM) Run ¶
func (instruction *InstructionSubAbsM) Run()
type InstructionSubM ¶
type InstructionSubM struct{}
SUB M(X)
func (*InstructionSubM) Run ¶
func (instruction *InstructionSubM) Run()
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) WriteLeftAddr ¶
func (m *Memory) WriteLeftAddr()
Write writes MBR[28:39] to M(X)[8:19]
func (*Memory) WriteRightAddr ¶
func (m *Memory) WriteRightAddr()
Write writes MBR[28:39] to M(X)[28:39]
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
func NewRegister ¶
func NewRegister() *Register
func (*Register) IsNegative ¶
type SimulateOption ¶
type SimulateOption func(*ExecuteParam)
func WithMaxSteps ¶
func WithMaxSteps(maxSteps int) SimulateOption
type Word ¶
type Word struct {
// contains filtered or unexported fields
}
One word has 40 bit
func NewWordFromData ¶
func NewWordFromHexStr ¶
func NewWordFromInt64 ¶
func (*Word) IsNegative ¶
Click to show internal directories.
Click to hide internal directories.