2024-06-10 13:51:39 +00:00
|
|
|
package asm
|
|
|
|
|
2024-06-15 09:36:57 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-08-07 17:39:10 +00:00
|
|
|
"git.akyoto.dev/cli/q/src/cpu"
|
2024-06-15 09:36:57 +00:00
|
|
|
)
|
2024-06-10 13:51:39 +00:00
|
|
|
|
|
|
|
// RegisterNumber operates with a register and a number.
|
|
|
|
type RegisterNumber struct {
|
2024-06-18 14:42:56 +00:00
|
|
|
Register cpu.Register
|
2024-06-24 14:55:15 +00:00
|
|
|
Number int
|
2024-06-10 13:51:39 +00:00
|
|
|
}
|
2024-06-15 09:36:57 +00:00
|
|
|
|
|
|
|
// String returns a human readable version.
|
|
|
|
func (data *RegisterNumber) String() string {
|
2024-06-26 20:51:14 +00:00
|
|
|
return fmt.Sprintf("%s, %d", data.Register, data.Number)
|
2024-06-15 09:36:57 +00:00
|
|
|
}
|
2024-07-12 22:13:13 +00:00
|
|
|
|
|
|
|
// RegisterNumber adds an instruction with a register and a number.
|
|
|
|
func (a *Assembler) RegisterNumber(mnemonic Mnemonic, reg cpu.Register, number int) {
|
|
|
|
a.Instructions = append(a.Instructions, Instruction{
|
|
|
|
Mnemonic: mnemonic,
|
|
|
|
Data: &RegisterNumber{
|
|
|
|
Register: reg,
|
|
|
|
Number: number,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|