drbfxb977777 2019-01-21 08:40
浏览 21
已采纳

如何使用go工具编译?

Simple code recursion and tails

package main

import "fmt"

func TailRecursive(number int, product int) int {

    product = product + number

    if number == 1 {

        return product
    }

    return TailRecursive(number-1, product)
}

func main() {

    answer := TailRecursive(5, 0)
    fmt.Printf("Recursive: %d
", answer)
}

When I try tool compile

go tool compile 6g -S ./g9.go > assembly.asm

I got this

 cat assembly.asm 
6g:0:0: open 6g: no such file or directory

My kernel architecture

x86_64 x86_64 x86_64 GNU/Linux

How to use go tool compile to get the proper assembly output?

  • 写回答

1条回答 默认 最新

  • donglu953744 2019-01-21 08:44
    关注

    Drop the 6g (it's now known as compile)

    go tool compile -S ./g9.go > assembly.asm
    

    Output

    "".TailRecursive STEXT size=107 args=0x18 locals=0x20
        0x0000 00000 (g9.go:5)  TEXT    "".TailRecursive(SB), $32-24
        0x0000 00000 (g9.go:5)  MOVQ    (TLS), CX
        0x0009 00009 (g9.go:5)  CMPQ    SP, 16(CX)
        0x000d 00013 (g9.go:5)  JLS 100
        0x000f 00015 (g9.go:5)  SUBQ    $32, SP
        0x0013 00019 (g9.go:5)  MOVQ    BP, 24(SP)
        0x0018 00024 (g9.go:5)  LEAQ    24(SP), BP
        0x001d 00029 (g9.go:5)  FUNCDATA    $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001d 00029 (g9.go:5)  FUNCDATA    $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001d 00029 (g9.go:5)  FUNCDATA    $3, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
        0x001d 00029 (g9.go:7)  PCDATA  $2, $0
        0x001d 00029 (g9.go:7)  PCDATA  $0, $0
        0x001d 00029 (g9.go:7)  MOVQ    "".number+40(SP), AX
        0x0022 00034 (g9.go:7)  MOVQ    "".product+48(SP), CX
        0x0027 00039 (g9.go:7)  ADDQ    AX, CX
        0x002a 00042 (g9.go:9)  CMPQ    AX, $1
        0x002e 00046 (g9.go:9)  JNE 63
        0x0030 00048 (g9.go:11) MOVQ    CX, "".~r2+56(SP)
        0x0035 00053 (g9.go:11) MOVQ    24(SP), BP
        0x003a 00058 (g9.go:11) ADDQ    $32, SP
        0x003e 00062 (g9.go:11) RET
        ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
  • ¥15 潜在扩散模型的Unet特征提取