q/src/asm/Instruction.go

30 lines
663 B
Go

package asm
import (
"fmt"
"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
Data []byte
}
// String returns the assembler representation of the instruction.
func (x *Instruction) String() string {
switch x.Mnemonic {
case MOV:
return fmt.Sprintf("%s %s, %x", x.Mnemonic, x.Destination, x.Number)
case MOVDATA:
return fmt.Sprintf("%s %s, %v", x.Mnemonic, x.Destination, x.Data)
case SYSCALL:
return x.Mnemonic.String()
default:
return ""
}
}