dongsha9208 2019-02-15 04:36
浏览 58
已采纳

golang asm代码中未知的“ ptr”变量

Recently I just begin to read the source code of atomic.LoadUint64, then I got an unknown variable "ptr" in the following asm code:

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

I couldn't find the declaration of this variable, and any documents about this variable, can anyone tell me about it?

  • 写回答

1条回答 默认 最新

  • doutong2132 2019-02-15 06:10
    关注

    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, in ptr+0(FP), is a name for the first argument to the function. The argument is probably a pointer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块