Improved assembler
This commit is contained in:
parent
d5f752bdd4
commit
8e193c69b6
22 changed files with 329 additions and 139 deletions
|
@ -1,8 +1,38 @@
|
|||
package asm
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
type Instruction interface {
|
||||
Write(io.ByteWriter)
|
||||
String() string
|
||||
"git.akyoto.dev/cli/q/src/asm/x64"
|
||||
"git.akyoto.dev/cli/q/src/register"
|
||||
)
|
||||
|
||||
// Instruction represents a single instruction which can be converted to machine code.
|
||||
type Instruction struct {
|
||||
Mnemonic Mnemonic
|
||||
Source register.ID
|
||||
Destination register.ID
|
||||
Number uint64
|
||||
}
|
||||
|
||||
// Write writes the machine code of the instruction.
|
||||
func (x *Instruction) Write(w io.ByteWriter) {
|
||||
switch x.Mnemonic {
|
||||
case MOV:
|
||||
x64.MoveRegNum32(w, uint8(x.Destination), uint32(x.Number))
|
||||
case SYSCALL:
|
||||
x64.Syscall(w)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Instruction) String() string {
|
||||
switch x.Mnemonic {
|
||||
case MOV:
|
||||
return fmt.Sprintf("%s %s, %x", x.Mnemonic, x.Destination, x.Number)
|
||||
case SYSCALL:
|
||||
return x.Mnemonic.String()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue