33 lines
735 B
Go
33 lines
735 B
Go
package asm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.akyoto.dev/cli/q/src/build/cpu"
|
|
)
|
|
|
|
// RegisterRegister operates with two registers.
|
|
type RegisterRegister struct {
|
|
Destination cpu.Register
|
|
Source cpu.Register
|
|
}
|
|
|
|
// String returns a human readable version.
|
|
func (data *RegisterRegister) String() string {
|
|
return fmt.Sprintf("%s, %s", data.Destination, data.Source)
|
|
}
|
|
|
|
// RegisterRegister adds an instruction using two registers.
|
|
func (a *Assembler) RegisterRegister(mnemonic Mnemonic, left cpu.Register, right cpu.Register) {
|
|
if a.unnecessary(mnemonic, left, right) {
|
|
return
|
|
}
|
|
|
|
a.Instructions = append(a.Instructions, Instruction{
|
|
Mnemonic: mnemonic,
|
|
Data: &RegisterRegister{
|
|
Destination: left,
|
|
Source: right,
|
|
},
|
|
})
|
|
}
|