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
+6.3k Golang : How to determine if request or crawl is from Google robots
+13.8k Golang : Google Drive API upload and rename example
+6.1k Golang : Detect face in uploaded photo like GPlus
+14.2k How to automatically restart your crashed Golang server
+51.1k Golang : Check if item is in slice/array
+12k Golang : 2 dimensional array example
+11.4k Golang : How to detect a server/machine network interface capabilities?
+4.9k Golang : Convert lines of string into list for delete and insert operation
+9.6k Golang : Function wrapper that takes arguments and return result example
+10.2k Golang : Allow Cross-Origin Resource Sharing request
+9.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+77.9k Golang : How to return HTTP status code?