30 lines
674 B
Go
30 lines
674 B
Go
package asm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.urbach.dev/cli/q/src/cpu"
|
|
)
|
|
|
|
// MemoryRegister operates with a memory address and a number.
|
|
type MemoryRegister struct {
|
|
Address Memory
|
|
Register cpu.Register
|
|
}
|
|
|
|
// String returns a human readable version.
|
|
func (data *MemoryRegister) String() string {
|
|
return data.Address.Format(fmt.Sprint(data.Register))
|
|
}
|
|
|
|
// MemoryRegister adds an instruction with a memory address and a number.
|
|
func (a *Assembler) MemoryRegister(mnemonic Mnemonic, address Memory, register cpu.Register) {
|
|
a.Instructions = append(a.Instructions, Instruction{
|
|
Mnemonic: mnemonic,
|
|
Data: &MemoryRegister{
|
|
Address: address,
|
|
Register: register,
|
|
},
|
|
})
|
|
}
|