英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论