如何获取一个简短的Go程序的汇编输出?

huangapple go评论94阅读模式
英文:

How to get assembly output for a short Go program?

问题

我有一个用Go语言编写的程序:

package main

func add(a, b int) int {
    return a + b
}

func main() {
    add(1, 2)
}

出于好奇,我想看看这个程序在汇编中是什么样子的。

我找到了几种从Go程序中输出汇编指令的方法,主要有:

go tool compile -S file.go > file.S

或者

go tool objdump executable > disassembly

但是似乎这两种方法产生的输出完全不同。

我该如何打印出组成我的Go程序的可读性强的汇编指令?

英文:

I have this program written in Go:

package main

func add(a, b int) int {
	return a + b
}

func main () {
	add(1,2)
}

For curiosity's sake, I would like to see what this program looks like in assembly.

I found a couple of ways to output assembly instructions from a Go program, mainly:

go tool compile -S file.go > file.S

Or

go tool objdump executable > disassembly

But it seems like both of these produce totally different outputs.

How can I print out human-readable assembly instructions that make up my Go program?

答案1

得分: 3

这两种方法都可以给你提供可读的汇编代码,只是Go工具链使用的是Plan 9汇编语法,对于不熟悉的人来说可能有些奇怪。你可以使用GNU binutils中的objdump工具来获取更熟悉的语法。

英文:

Both of these give you human-readable assembly, it's just that the Go toolchain uses Plan 9 assembly syntax which is a bit weird to the untrained eye. Use a tool like objdump from the GNU binutils to get more familiar syntax.

huangapple
  • 本文由 发表于 2017年5月9日 06:43:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/43858356.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定