Improved assembler
This commit is contained in:
42
src/asm/Assembler.go
Normal file
42
src/asm/Assembler.go
Normal file
@ -0,0 +1,42 @@
|
||||
package asm
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/register"
|
||||
)
|
||||
|
||||
// Assembler contains a list of instructions.
|
||||
type Assembler struct {
|
||||
Instructions []Instruction
|
||||
}
|
||||
|
||||
// New creates a new assembler.
|
||||
func New() *Assembler {
|
||||
return &Assembler{
|
||||
Instructions: make([]Instruction, 0, 8),
|
||||
}
|
||||
}
|
||||
|
||||
// Finalize generates the final machine code.
|
||||
func (list *Assembler) Finalize() *Result {
|
||||
final := Result{}
|
||||
|
||||
for _, instr := range list.Instructions {
|
||||
instr.Write(&final.Code)
|
||||
}
|
||||
|
||||
return &final
|
||||
}
|
||||
|
||||
func (list *Assembler) MoveRegisterNumber(reg register.ID, number uint64) {
|
||||
list.Instructions = append(list.Instructions, Instruction{
|
||||
Mnemonic: MOV,
|
||||
Destination: reg,
|
||||
Number: number,
|
||||
})
|
||||
}
|
||||
|
||||
func (list *Assembler) Syscall() {
|
||||
list.Instructions = append(list.Instructions, Instruction{
|
||||
Mnemonic: SYSCALL,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user