import "cmd/internal/obj" // Create an Addr representing an address of 0x1000 addr := obj.Addr{Type: obj.TYPE_MEM, Offset: 0x1000} // Add 4 bytes to the address addr = addr.Add(4) // Subtract 2 bytes from the address addr = addr.Sub(2) // Compare the address to another address otherAddr := obj.Addr{Type: obj.TYPE_MEM, Offset: 0x0FFF} if addr.Cmp(otherAddr) > 0 { // addr is greater than otherAddr }
import "cmd/internal/obj" // Create an Addr representing a PC-relative address addr := obj.Addr{Type: obj.TYPE_BRANCH, Offset: 0x100, Sym: &obj.LSym{}} // Set the symbol associated with the address sym := &obj.LSym{} addr.SetSym(sym) // Get the symbol associated with the address sym = addr.Sym.(*obj.LSym)In this example, we create an Addr representing a PC-relative address with a symbol. We then set and get the symbol using the SetSym and Sym methods. The package library for cmd/internal/obj is cmd/internal/obj.