August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, we are going to talk about assembly and Go, and how you can use assembly to implement Go functions. We will begin with the following Go program, which is saved as add_me.go:
package main
import (
"fmt"
)
func add(x, y int64) int64 {
return x + y
}
func main() {
fmt.Println(add(1, 2))
}
Executing the following command will reveal the assembly implementation of the add() function, which is the following:
$ GOOS=darwin GOARCH=amd64 go tool compile -S add_me.go
"".add STEXT nosplit size=19 args=0x18 locals=0x0
0x0000 00000 (add_me.go:7) TEXT "".add(SB), NOSPLIT|ABIInternal, $0-24
0x0000 00000 (add_me.go:7) FUNCDATA $0, gclocals 33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (add_me.go:7) FUNCDATA ...Read now
Unlock full access