assembler

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RegLabel is a placeholder register value indicating a label to be resolved.
	RegLabel = 0xFE
	// RegStatus is a placeholder register value indicating a status register (SR/CCR/USP).
	RegStatus = 0xFFFF
)

Variables

View Source
var (

	// SizeBits is for dual-operand instructions (ADD, SUB, OR, AND, etc.)
	SizeBits = commonSizeBits
	// SizeBitsSingleOp is for single-operand instructions (CLR, NEG, NOT, etc.)
	SizeBitsSingleOp = commonSizeBits
	// SizeBitsTst is for the TST instruction (same pattern as dual-operand instructions).
	SizeBitsTst = commonSizeBits

	// SizeBitsAddr is for ADDA, SUBA, CMPA (address arithmetic)
	SizeBitsAddr = map[cpu.Size]uint16{
		cpu.SizeWord: 0x00C0,
		cpu.SizeLong: 0x01C0,
	}
)
View Source
var BitwiseSize = map[cpu.Size]uint16{
	cpu.SizeByte: 0x0000,
	cpu.SizeWord: 0x0040,
	cpu.SizeLong: 0x0080,
}

BitwiseSize contains size bits for shift/rotate register forms.

View Source
var ShiftRotateType = map[string]uint16{
	"asr": 0x0000, "asl": 0x0100,
	"lsr": 0x0008, "lsl": 0x0108,
	"ror": 0x0018, "rol": 0x0118,
	"roxr": 0x0010, "roxl": 0x0110,
}

ShiftRotateType contains shift/rotate opcode type bits (added to base opcode).

Functions

This section is empty.

Types

type Assembler

type Assembler struct {
	// contains filtered or unexported fields
}

Assembler holds the state for the assembly process.

func New

func New() *Assembler

New creates a new Assembler instance.

func (*Assembler) Assemble

func (asm *Assembler) Assemble(src string, baseAddress uint32) ([]byte, error)

Assemble takes M68k assembly code and returns the machine code.

func (*Assembler) CanBeMoveq added in v0.4.0

func (asm *Assembler) CanBeMoveq(mn Mnemonic, src Operand, dst Operand) bool

CanBeMoveq checks if the instruction can be encoded as MOVEQ. MOVEQ encodes an immediate signed 8-bit constant (-128..127) into a data register.

type Mnemonic

type Mnemonic struct {
	Value string
	Size  cpu.Size
}

Mnemonic represents a parsed instruction mnemonic.

func ParseMnemonic

func ParseMnemonic(s string) (Mnemonic, error)

ParseMnemonic splits an instruction like "MOVE.W" → ("move", SizeWord).

type Node

type Node struct {
	Type     NodeType
	Label    string
	Mnemonic Mnemonic
	Operands []Operand
	Parts    []string
	Size     uint32 // Still used to track size between passes
}

Node represents one parsed element from the assembly source.

type NodeType

type NodeType int

NodeType defines the type of an assembly node.

const (
	// NodeInstruction type.
	NodeInstruction NodeType = iota
	// NodeLabel type.
	NodeLabel
	// NodeDirective type.
	NodeDirective
)

type Operand

type Operand struct {
	Mode           uint16
	Register       uint16
	ExtensionWords []uint16
	Raw            string
	Label          string
}

Operand represents a parsed instruction operand.

func (*Operand) IsImmediate

func (o *Operand) IsImmediate() bool

IsImmediate returns true if this operand is an immediate constant.

Jump to

Keyboard shortcuts

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