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.

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

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器