golang 中的汇编

个00个 · · 1509 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

简单的源码

package main

func main(){
}

生成汇编的代码

go tool compile -S -l  test.go
-S 是打印汇编
-l 是防止内联

生成的汇编

"".main STEXT nosplit size=1 args=0x0 locals=0x0
        0x0000 00000 (test.go:3)        TEXT    "".main(SB), NOSPLIT, $0-0
        # "".main(SB)  函数名称  (SB -> static base)
        # NOSPLIT  无需提供参数大小
        # $0-0  (局部变量的大小字节数) - (传入参数 + 返回值所占的字节数)                                             
        0x0000 00000 (test.go:3)        FUNCDATA        $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x0000 00000 (test.go:3)        FUNCDATA        $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x0000 00000 (test.go:3)        FUNCDATA        $3, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        # FUNCDATA  跟gc的垃圾回收有关... 编译器自动生成的
        0x0000 00000 (test.go:4)        RET
        # RET  函数返回
        0x0000 c3                                               .
"".init STEXT size=80 args=0x0 locals=0x8
        0x0000 00000 (<autogenerated>:1)        TEXT    "".init(SB), $8-0
        0x0000 00000 (<autogenerated>:1)        MOVQ    (TLS), CX
        0x0009 00009 (<autogenerated>:1)        CMPQ    SP, 16(CX)
        0x000d 00013 (<autogenerated>:1)        JLS     73
        0x000f 00015 (<autogenerated>:1)        SUBQ    $8, SP
        0x0013 00019 (<autogenerated>:1)        MOVQ    BP, (SP)
        0x0017 00023 (<autogenerated>:1)        LEAQ    (SP), BP
        0x001b 00027 (<autogenerated>:1)        FUNCDATA        $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001b 00027 (<autogenerated>:1)        FUNCDATA        $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001b 00027 (<autogenerated>:1)        FUNCDATA        $3, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001b 00027 (<autogenerated>:1)        PCDATA  $2, $0
        0x001b 00027 (<autogenerated>:1)        PCDATA  $0, $0
        0x001b 00027 (<autogenerated>:1)        MOVBLZX "".initdone·(SB), AX
        0x0022 00034 (<autogenerated>:1)        CMPB    AL, $1
        0x0025 00037 (<autogenerated>:1)        JLS     48
        0x0027 00039 (<autogenerated>:1)        PCDATA  $2, $-2
        0x0027 00039 (<autogenerated>:1)        PCDATA  $0, $-2
        0x0027 00039 (<autogenerated>:1)        MOVQ    (SP), BP
        0x002b 00043 (<autogenerated>:1)        ADDQ    $8, SP
        0x002f 00047 (<autogenerated>:1)        RET
        0x0030 00048 (<autogenerated>:1)        JNE     57
        0x0032 00050 (<autogenerated>:1)        PCDATA  $2, $0
        0x0032 00050 (<autogenerated>:1)        PCDATA  $0, $0
        0x0032 00050 (<autogenerated>:1)        CALL    runtime.throwinit(SB)
        0x0037 00055 (<autogenerated>:1)        UNDEF
        0x0039 00057 (<autogenerated>:1)        MOVB    $2, "".initdone·(SB)
        0x0040 00064 (<autogenerated>:1)        MOVQ    (SP), BP
        0x0044 00068 (<autogenerated>:1)        ADDQ    $8, SP
        0x0048 00072 (<autogenerated>:1)        RET
        0x0049 00073 (<autogenerated>:1)        NOP
        0x0049 00073 (<autogenerated>:1)        PCDATA  $0, $-1
        0x0049 00073 (<autogenerated>:1)        PCDATA  $2, $-1
        0x0049 00073 (<autogenerated>:1)        CALL    runtime.morestack_noctxt(SB)
        0x004e 00078 (<autogenerated>:1)        JMP     0
        0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 3a 48  dH..%....H;a.v:H
        0x0010 83 ec 08 48 89 2c 24 48 8d 2c 24 0f b6 05 00 00  ...H.,$H.,$.....
        0x0020 00 00 80 f8 01 76 09 48 8b 2c 24 48 83 c4 08 c3  .....v.H.,$H....
        0x0030 75 07 e8 00 00 00 00 0f 0b c6 05 00 00 00 00 02  u...............
        0x0040 48 8b 2c 24 48 83 c4 08 c3 e8 00 00 00 00 eb b0  H.,$H...........
        rel 5+4 t=16 TLS+0
        rel 30+4 t=15 "".initdone·+0
        rel 51+4 t=8 runtime.throwinit+0
        rel 59+4 t=15 "".initdone·+-1
        rel 74+4 t=8 runtime.morestack_noctxt+0
go.loc."".main SDWARFLOC size=0
go.info."".main SDWARFINFO size=33
        0x0000 02 22 22 2e 6d 61 69 6e 00 00 00 00 00 00 00 00  ."".main........
        0x0010 00 00 00 00 00 00 00 00 00 01 9c 00 00 00 00 01  ................
        0x0020 00                                               .
        rel 9+8 t=1 "".main+0
        rel 17+8 t=1 "".main+1
        rel 27+4 t=29 gofile../home/work/workspace/Go/src/shenshida.com/hello/test/test.go+0
go.range."".main SDWARFRANGE size=0
go.isstmt."".main SDWARFMISC size=0
        0x0000 04 01 00                                         ...
go.loc."".init SDWARFLOC size=0
go.info."".init SDWARFINFO size=33
        0x0000 02 22 22 2e 69 6e 69 74 00 00 00 00 00 00 00 00  ."".init........
        0x0010 00 00 00 00 00 00 00 00 00 01 9c 00 00 00 00 01  ................
        0x0020 00                                               .
        rel 9+8 t=1 "".init+0
        rel 17+8 t=1 "".init+80
        rel 27+4 t=29 gofile..<autogenerated>+0
go.range."".init SDWARFRANGE size=0
go.isstmt."".init SDWARFMISC size=0
        0x0000 04 0f 04 0c 03 07 01 05 02 09 01 07 02 09 01 09  ................
        0x0010 02 07 00                                         ...
"".initdone· SNOPTRBSS size=1
gclocals·33cdeccccebe80329f1fdbee7f5874cb SRODATA dupok size=8
        0x0000 01 00 00 00 00 00 00 00                          ........

剩下的好多我也看不懂呀。。。难受想哭
自动生成的好多都看不懂。


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:个00个

查看原文:golang 中的汇编

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1509 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传