请教 ch3-05-control-flow if跳转问题
ahcometrue opened this issue · 1 comments
ahcometrue commented
- 汇编代码
#include "textflag.h"
TEXT ·If(SB), NOSPLIT, $0-32
MOVQ ok+8*0(FP), CX // ok
MOVQ a+8*1(FP), AX // a
MOVQ b+8*2(FP), BX // b
CMPQ CX, $0 // test ok
JZ L // if ok == 0, goto L
MOVQ AX, ret+24(FP) // return a
RET
L:
MOVQ BX, ret+24(FP) // return b
RET
- go代码
func If(ok int, a, b int) int {
if ok == 0 { goto L }
return a
L:
return b
}
运行时报错:
# command-line-arguments
duplicated definition of symbol assembly/func.If
cch123 commented
重复定义了吧,汇编里有代码的话,go 里写个函数头就能用了