Skip to main content

Go Asm

📅 2026-02-05 ✏️ 2026-03-06 CS GO
No related notes

go asm

4 pseudo-registers: virtual registers maintained by the toolchain;

FP: Frame pointer: arguments and locals. PC: Program counter: jumps and branches. SB: Static base pointer: global symbols. SP: Stack pointer: the highest address within the local stack frame.

All user-defined symbols are written as offsets to the pseudo-registers FP (arguments and locals) and SB (globals).

SB: foo(SB) is used to name global functions and data; Adding <> to the name, as in foo<>(SB), makes the name visible only in the current source file; Adding an offset to the name refers to that offset from the symbol’s address, foo+4(SB) is four bytes past the start of foo.

FP: which is a virtual frame pointer used to refer to function arguments(that offset the FP register); ‘tis necessary to place a name at the beginning, as in first_arg+0(FP) and second_arg+8(FP); FP is always a pseudo-register, not a hardware register.

SP: which is a virtual stack pointer used to refer to frame-local variables and the arguments; it points to the highest address within the local stack frame, so references should use negative offsets in the range [−framesize, 0); the name prefix distinguishes references to the virtual stack pointer from references to the architectural SP register, x-8(SP) => virtual SP, -8(SP) => hardware SP;

On machines where SP and PC are traditionally aliases for a physical, numbered register, in the Go assembler the names SP and PC are still treated specially; for instance, references to SP require a symbol, much like FP. To access the actual hardware register use the true R name. For example, on the ARM architecture the hardware SP and PC are accessible as R13 and R15.

Branches and direct jumps are always written as offsets to the PC, or as jumps to labels; the linker inserts the package path of the current object file at the beginning of any name starting with a period; ·Int => math/rand·Int

directive symbol,instructions,frameSize[-argumentSize] TEXT runtime·profileloop(SB),NOSPLIT,$8 MOVQ $runtime·profileloop1(SB), CX MOVQ CX, 0(SP) CALL runtime·externalthreadhandler(SB) RET

Argument live on the caller’s frame; If NOSPLIT is not specified for the TEXT, the argument size must be provided;

the symbol name uses a middle dot · to separate the components; which is specified as an offset from the static base pseudo-register SB; would be called from Go source for package before · using the simple name after ·.

Global data symbols: a sequence of initializing DATA directives followed by a GLOBL directive; DATA symbol+offset(SB)/width, value1 DATA symbol+offset(SB)/width, value2 … GLOBAL symbol,optional-flags,dataSize

DATA: GLOBL: initial value all zeros unless a DATA directive has initialized it, must follow any corresponding DATA directives

a bit mask of flags defined in the standard #include file textflag.h.

Interacting with Go types and constants: const_name, type_field, type__size…

Runtime Coordination: for GC, the runtime must know the location of pointers in all global data and in most stack frames.