From: Russ Cox A Quick Guide to Go's Assembler
@@ -113,12 +113,30 @@ is the name foo
as an address in memory.
-The FP
is a virtual frame pointer.
+The FP
pseudo-register is a virtual frame pointer
+used to refer to function arguments.
The compilers maintain a virtual frame pointer and refer to the arguments on the stack as offsets from that pseudo-register.
Thus 0(FP)
is the first argument to the function,
8(FP)
is the second (on a 64-bit machine), and so on.
-To refer to an argument by name, add the name to the numerical offset, like this: first_arg+0(FP)
.
-The name in this syntax has no semantic value; think of it as a comment to the reader.
+When referring to a function argument this way, it is conventional to place the name
+at the beginning, as in first_arg+0(FP)
and second_arg+8(FP)
.
+Some of the assemblers enforce this convention, rejecting plain 0(FP)
and 8(FP)
.
+For assembly functions with Go prototypes, go vet
will check that the argument names
+and offsets match.
+
+The SP
pseudo-register is a virtual stack pointer
+used to refer to frame-local variables and the arguments being
+prepared for function calls.
+It points to the top of the local stack frame, so references should use negative offsets
+in the range [âframesize, 0):
+x-8(SP)
, y-4(SP)
, and so on.
+On architectures with a real register named SP
, the name prefix distinguishes
+references to the virtual stack pointer from references to the architectural SP
register.
+That is, x-8(SP)
and -8(SP)
are different memory locations:
+the first refers to the virtual stack pointer pseudo-register, while the second refers to the
+hardware's SP
register.
@@ -358,11 +376,26 @@ MOVQ m(CX), BX // Move m into BX.
-The registers R9
and R10
are reserved by the
-compiler and linker to point to the m
(machine) and g
+The registers R9
, R10
, and R11
+are reserved by the compiler and linker.
+
+R9
and R10
point to the m
(machine) and g
(goroutine) structures, respectively.
-Within assembler source code, these pointers
-can be referred to as simply m
and g
.
+Within assembler source code, these pointers must be referred to as m
and g
;
+the names R9
and R10
are not recognized.
+
+To make it easier for people and compilers to write assembly, the ARM linker
+allows general addressing forms and pseudo-operations like DIV
or MOD
+that may not be expressible using a single hardware instruction.
+It implements these forms as multiple instructions, often using the R11
register
+to hold temporary values.
+Hand-written assembly can use R11
, but doing so requires
+being sure that the linker is not also using it to implement any of the other
+instructions in the function.
@@ -370,6 +403,10 @@ When defining a TEXT
, specifying frame size $-4
tells the linker that this is a leaf function that does not need to save LR
on entry.
+The name SP
always refers to the virtual stack pointer described earlier.
+For the hardware register, use R13
.
+