bbasm

package
v1.0.1-0...-764e6f0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDataToShort = errors.NewClass("ErrDataToShort")
View Source
var ErrWrongInst = errors.NewClass("ErrWrongInst")

Functions

func Calculate

func Calculate(a int, b int, t CalculateType, d DataType) int

func Compare

func Compare(a Operand, b Operand, d DataType) int

func Execute

func Execute(ctx context.Context, rt Runtime, inst *Inst)

Types

type AddressMode

type AddressMode uint8
const (
	AddressRegister         AddressMode = iota // 寄存器寻址
	AddressRegisterDeferred                    // 寄存器间接寻址
	AddressImmediate                           // 立即数
	AddressDirect                              // 直接寻址
)

func (AddressMode) String

func (v AddressMode) String() string

type CalculateType

type CalculateType uint8
const (
	ADD CalculateType = iota
	SUB
	MUL
	DIV
	MOD
)

func (CalculateType) String

func (c CalculateType) String() string

type CompareType

type CompareType uint8
const (
	Z  CompareType = iota + 1 // Equal
	B                         // Blow
	BE                        // Blow or Equal
	A                         // Above
	AE                        // Above or Equal
	NZ                        // Not Equal
)

func (CompareType) IsMatch

func (ct CompareType) IsMatch(b CompareType) bool

func (CompareType) String

func (ct CompareType) String() string

type DataType

type DataType uint8
const (
	DWORD DataType = iota
	WORD
	BYTE
	FLOAT
	INT
)

func (DataType) String

func (t DataType) String() string

type Inst

type Inst struct {
	DataType      DataType
	CompareType   CompareType
	CalculateType CalculateType
	Opcode        Opcode
	A             Operand
	B             Operand

	Line    int
	Comment string
}

func (Inst) Assembly

func (i Inst) Assembly() (s string)

func (*Inst) GetComment

func (i *Inst) GetComment() string

func (*Inst) Len

func (i *Inst) Len() int

func (*Inst) MarshalBinary

func (i *Inst) MarshalBinary() ([]byte, error)

func (*Inst) SetComment

func (i *Inst) SetComment(v string)

func (*Inst) UnmarshalBinary

func (i *Inst) UnmarshalBinary(data []byte) error

type Memory

type Memory interface {
	GetInt(int) int
	SetInt(int, int)
	GetFloat(int) float32
	SetFloat(int, float32)
	GetString(int) string
}

type Opcode

type Opcode uint8
const (
	NOP Opcode = iota
	LD
	PUSH
	POP
	IN
	OUT
	JMP
	JPC
	CALL
	RET
	CMP
	CAL
	EXIT Opcode = 0xF
)

func (Opcode) Len

func (o Opcode) Len() int

func (Opcode) String

func (o Opcode) String() string

type Operand

type Operand struct {
	V           int32 // Address or Immediate value
	AddressMode AddressMode
	RT          Runtime
	Symbol      string // Symbol associated to this operand - run from assembly
}

func (*Operand) Float

func (o *Operand) Float() float32

func (*Operand) Get

func (o *Operand) Get() int

func (*Operand) Set

func (o *Operand) Set(i int)

func (*Operand) SetFloat

func (o *Operand) SetFloat(v float32)

func (Operand) String

func (o Operand) String() string

type Register

type Register interface {
	Get() int
	Set(int)
	Float() float32
	SetFloat(v float32)
}

type RegisterType

type RegisterType uint8
const (
	RP RegisterType = iota // 程序计数器,指令寻址寄存器
	RF                     // 标志寄存器,存储比较操作结果
	RS                     // 栈寄存器 - 空栈顶地址,指向的是下一个准备要压入数据的位置
	RB                     // 辅助栈寄存器 - 栈开始的地址(文件长度+2)
	R0                     // #0 寄存器
	R1                     // #1 寄存器
	R2                     // #2 寄存器
	R3                     // #3 寄存器
)

func (RegisterType) String

func (r RegisterType) String() string

type Runtime

type Runtime interface {
	Memory

	Push(val int) // push stack
	Pop() int     // pop stack
	Register(typ RegisterType) Register
	Jump(addr int)
	Exit()
	In(ctx context.Context, a int, b int)
	Out(ctx context.Context, a int, b int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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