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
+22.4k Golang : untar or extract tar ball archive example
+5.8k Golang : Missing Subversion command
+10.9k CodeIgniter : How to check if a session exist in PHP?
+6.6k Get Facebook friends working in same company
+5.1k Unix/Linux : How to archive and compress entire directory ?
+34.9k Golang : Strip slashes from string example
+15.9k Golang : How to extract links from web page ?
+6.4k Golang : Check if password length meet the requirement
+51k Golang : Check if item is in slice/array
+5.8k Golang : Create new color from command line parameters
+7.1k Golang : Process json data with Jason package