package asm import ( "fmt" "math" "strconv" "strings" "git.urbach.dev/cli/q/src/cpu" ) type Memory struct { Base cpu.Register Offset int8 OffsetRegister cpu.Register Length byte } // Format returns a human readable version. func (mem *Memory) Format(custom string) string { tmp := strings.Builder{} tmp.WriteString("[") tmp.WriteString(fmt.Sprint(mem.Base)) if mem.OffsetRegister != math.MaxUint8 { tmp.WriteString("+") tmp.WriteString(fmt.Sprint(mem.OffsetRegister)) } if mem.Offset != 0 { if mem.Offset > 0 { tmp.WriteString("+") } tmp.WriteString(strconv.Itoa(int(mem.Offset))) } tmp.WriteString("], ") tmp.WriteString(custom) tmp.WriteString(", ") tmp.WriteString(strconv.Itoa(int(mem.Length))) return tmp.String() }