Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active March 10, 2021 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icholy/ae4ca73e97210fdb3e01415978d0ce07 to your computer and use it in GitHub Desktop.
Save icholy/ae4ca73e97210fdb3e01415978d0ce07 to your computer and use it in GitHub Desktop.
package main

//go:noinline
func thing(values ...string) {
	for _, v := range values {
		println(v)
	}
}

func main() {
	thing("a", "b", "c")
}
XORPS	X0, X0                     // zero out reg X0
MOVUPS	X0, array_elem_0+24(SP)    // set 24(SP) to 0
MOVUPS	X0, array_elem_1+40(SP)    // set 40(SP) to 0
MOVUPS	X0, array_elem_2+56(SP)    // set 56(SP) to 0
LEAQ	go.string."a"(SB), AX      // put the address of static "a" in AX
MOVQ	AX, array_elem_0+24(SP)    // put the address of static "a" into 24(SP)
MOVQ	$1, array_elem_0+32(SP)    // put the value 1 into 32(SP)
LEAQ	go.string."b"(SB), AX      // put the address of static "b" into AX
MOVQ	AX, array_elem_1+40(SP)    // put the address of static "b" into 40(SP)
MOVQ	$1, array_elem_1+48(SP)    // put the value 1 into 48(SP)
LEAQ	go.string."c"(SB), AX      // put the address of static "c" into AX
MOVQ	AX, array_elem_2+56(SP)    // put the address of static "c" into 56(SP)
MOVQ	$1, array_elem_2+64(SP)    // put the value 1 into 64(SP)
LEAQ	array_elem_0+24(SP), AX    // put the address of the array into AX
MOVQ	AX, (SP)                   // put the address of the array into 0(SP)
MOVQ	$3, 8(SP)                  // set the size of the slice into 8(SP)
MOVQ	$3, 16(SP)                 // set the capacity of the slice into 16(SP)
| STACK FRAME
-------------------
| 80 |
| 72 |
| 64 | 1      // string size
| 56 | &"c"   // string data pointer
| 48 | 1      // string size
| 40 | &"b"   // string data pointer
| 32 | 1      // string size
| 24 | &"a"   // string data pointer (first element in array)
| 16 | 3                         // slice capacity
| 8  | 3                         // slice size
| 0  | &[3]string{"a", "b", "c"} // points to SP(24) ie slice header data pointer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment