Golang : Convert source code to assembly language
If you ever have the urge to convert your Golang source code to assembly language, check out this online tool :
One draw back about http://go.godbolt.org/ is that it cannot disassemble third-parties packges (such as those in the import block ).
To get full assembly source code from your Golang code, use this command go build -gcflags -S
For example :
package main
import "fmt"
func main() {
fmt.Println("Hello World!");
}
go build -gcflags -S hello.go
will produce :
# command-line-arguments
"".main t=1 size=240 value=0 args=0x0 locals=0x78
0x0000 00000 (/root/hello.go:5) TEXT "".main+0(SB),$120-0
0x0000 00000 (/root/hello.go:5) MOVQ (TLS),CX
0x0009 00009 (/root/hello.go:5) CMPQ SP,16(CX)
0x000d 00013 (/root/hello.go:5) JHI ,22
0x000f 00015 (/root/hello.go:5) CALL ,runtime.morestack_noctxt(SB)
0x0014 00020 (/root/hello.go:5) JMP ,0
0x0016 00022 (/root/hello.go:5) SUBQ $120,SP
0x001a 00026 (/root/hello.go:5) FUNCDATA $0,gclocals·73423680ca5f2d7df4fe760a82d507fb+0(SB)
0x001a 00026 (/root/hello.go:5) FUNCDATA $1,gclocals·1eb9d8ec9969f1d922533aa863dff6f6+0(SB)
0x001a 00026 (/root/hello.go:7) LEAQ go.string."Hello World!"+0(SB),BX
0x0021 00033 (/root/hello.go:7) MOVQ (BX),BP
0x0024 00036 (/root/hello.go:7) MOVQ BP,"".autotmp_0001+64(SP)
0x0029 00041 (/root/hello.go:7) MOVQ 8(BX),BP
0x002d 00045 (/root/hello.go:7) MOVQ BP,"".autotmp_0001+72(SP)
0x0032 00050 (/root/hello.go:7) LEAQ "".autotmp_0000+80(SP),BX
0x0037 00055 (/root/hello.go:7) MOVQ $0,(BX)
0x003e 00062 (/root/hello.go:7) MOVQ $0,8(BX)
0x0046 00070 (/root/hello.go:7) LEAQ "".autotmp_0000+80(SP),BX
0x004b 00075 (/root/hello.go:7) CMPQ BX,$0
0x004f 00079 (/root/hello.go:7) JEQ $1,223
0x0055 00085 (/root/hello.go:7) MOVQ $1,DX
0x005c 00092 (/root/hello.go:7) MOVQ $1,CX
...
Good read : https://blog.cloudflare.com/go-crypto-bridging-the-performance-gap/
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+16.3k Golang : Delete files by extension
+10.7k Nginx : TLS 1.2 support
+47.7k Golang : How to convert JSON string to map and slice
+10.3k Golang : Allow Cross-Origin Resource Sharing request
+9.9k Golang : Edge detection with Sobel method
+13.8k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+15.1k Golang : Delete certain files in a directory
+13.2k Golang : How to get year, month and day?
+9.5k Golang : Qt get screen resolution and display on center example
+7.3k Golang : Gorrila set route name and get the current route name
+8.3k Golang : Another camera capture GUI application with GTK and OpenCV