gpt4 book ai didi

go - golang asm 代码中的未知 "ptr"变量

转载 作者:IT王子 更新时间:2023-10-29 02:19:43 26 4
gpt4 key购买 nike

最近刚开始看atomic.LoadUint64的源码,在下面的asm代码中得到了一个未知的变量“ptr”:

TEXT runtime∕internal∕atomic·Load64(SB), NOSPLIT, $0-12                                                                                                                                                                                       
MOVL ptr+0(FP), AX
TESTL $7, AX
JZ 2(PC)
MOVL 0, AX // crash with nil ptr deref
MOVQ (AX), M0
MOVQ M0, ret+4(FP)
EMMS
RET

我找不到这个变量的声明,也找不到任何关于这个变量的文档,谁能告诉我吗?

最佳答案

A Quick Guide to Go's Assembler

Symbols

The FP pseudo-register is a virtual frame pointer used to refer to function arguments. The compilers maintain a virtual frame pointer and refer to the arguments on the stack as offsets from that pseudo-register. Thus 0(FP) is the first argument to the function, 8(FP) is the second (on a 64-bit machine), and so on. However, when referring to a function argument this way, it is necessary to place a name at the beginning, as in first_arg+0(FP) and second_arg+8(FP). (The meaning of the offset—offset from the frame pointer—distinct from its use with SB, where it is an offset from the symbol.) The assembler enforces this convention, rejecting plain 0(FP) and 8(FP). The actual name is semantically irrelevant but should be used to document the argument's name. It is worth stressing that FP is always a pseudo-register, not a hardware register, even on architectures with a hardware frame pointer.


ptr,在 ptr+0(FP) 中,是函数第一个参数的名称。参数可能是一个指针。

关于go - golang asm 代码中的未知 "ptr"变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54702748/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com