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 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度