package asm import ( "fmt" "math" ) // MemoryLabel operates with a memory address and a number. type MemoryLabel struct { Label string Address Memory } // String returns a human readable version. func (data *MemoryLabel) String() string { if data.Address.OffsetRegister == math.MaxUint8 { return fmt.Sprintf("%dB [%s+%d], %s", data.Address.Length, data.Address.Base, data.Address.Offset, data.Label) } return fmt.Sprintf("%dB [%s+%s+%d], %s", data.Address.Length, data.Address.Base, data.Address.OffsetRegister, data.Address.Offset, data.Label) } // MemoryLabel adds an instruction with a memory address and a label. func (a *Assembler) MemoryLabel(mnemonic Mnemonic, address Memory, label string) { a.Instructions = append(a.Instructions, Instruction{ Mnemonic: mnemonic, Data: &MemoryLabel{ Address: address, Label: label, }, }) }