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
+11.1k Golang : Characters limiter example
+3.1k Golang : Fix go-cron set time not working issue
+12.4k Golang : Remove or trim extra comma from CSV
+14k Golang : Convert IP version 6 address to integer or decimal number
+10.9k Google Maps URL parameters configuration
+6.1k Golang : How to get capacity of a slice or array?
+10.9k Golang : Fix - does not implement sort.Interface (missing Len method)
+15.7k Golang : Read a file line by line
+4.6k Golang : A program that contain another program and executes it during run-time
+5k Golang : The Tao of importing package
+12.4k Golang : Sort and reverse sort a slice of bytes