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
+10.6k CodeIgniter : Import Linkedin data
+11.2k Golang : Extract part of string with regular expression
+5.7k Golang : Reverse by word
+3.9k Which content-type(MIME type) to use for JSON data
+45.5k Golang : Convert int to byte array([]byte)
+10.4k Golang : Concurrency and goroutine example
+8.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+4.3k Golang : How to deal with configuration data?
+10k Golang : How to use if, eq and print properly in html template
+6.6k Golang : Generate human readable password
+28.3k Golang : Get and Set User-Agent examples
+15.4k Golang : Set up source IP address before making HTTP request