将星星放在寄存器前是什么意思? [英] what is the meaning of putting a star before a register?

查看:149
本文介绍了将星星放在寄存器前是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究c ++如何通过汇编语言调用正确的成员函数. 我附带的简单程序如下:

I am studying how c++ invoke the right member functions through assembly language. The simple program that I come with is as the following:

class A                        
{                              
    public:                    
        virtual void show() {} 
};                             

class B : public A             
{                              
    public:                    
        void show() {}         
};                             


int main()                     
{                              
    A* pA = new B;             
    pA->show();                

    return 0;                  
}                              

其汇编如下:

main:
.LFB2:
    .cfi_startproc
    .cfi_personality 0x3,__gxx_personality_v0
    pushq   %rbp
    .cfi_def_cfa_offset 16
    movq    %rsp, %rbp
    .cfi_offset 6, -16
    .cfi_def_cfa_register 6
    pushq   %rbx
    subq    $24, %rsp
    movl    $8, %edi
    .cfi_offset 3, -24
    call    _Znwm            <<<================ 1
    movq    %rax, %rbx
    movq    %rbx, %rax
    movq    %rax, %rdi
    call    _ZN1BC1Ev
.L11:
    movq    %rbx, %rax
    movq    %rax, -24(%rbp)
    movq    -24(%rbp), %rax
    movq    (%rax), %rax
    movq    (%rax), %rdx
    movq    -24(%rbp), %rax
    movq    %rax, %rdi
    call    *%rdx             <<<=== 2
    movl    $0, %eax
    addq    $24, %rsp
    popq    %rbx
    leave
    ret
    .cfi_endproc

我的问题是:

  1. 我在google中搜索了nwm,它只告诉我c ++使用它来分配内存, 有人可以告诉我更多吗?在一个库中吗? 如果可能,我可以获取其源代码吗?怎么样?
  2. 我对这种语法不太熟悉,它想做什么?
  1. I searched google for nwm, it only tells me that c++ uses it to allocate memory, could some one tell me more about it ? is it in one lib? if possible, can i get its source code? how?
  2. i am not quite familiar with this syntax, what does it want to do ?

推荐答案

*在AT& T汇编语法中的绝对地址之前用于调用或跳转指令.这意味着它将跳转到寄存器中包含的地址.另一种选择是相对跳转,它相对于当前指令.

The * is used before absolute addresses in AT&T assembly syntax for call or jump instructions. This means it will jump to the address contained in the register. The alternative is a relative jump, which is relative to the current instruction.

GNU as手册:

AT& T绝对值(相对于PC相对值) 跳转/调用操作数以"*"为前缀;他们在 英特尔语法.

AT&T absolute (as opposed to PC relative) jump/call operands are prefixed by `*'; they are undelimited in Intel syntax.

在您的代码中,有必要调用寄存器中的地址.调用pA->show()需要进行查找,以查看要调用的正确函数是什么.这是因为它是类A上的虚函数.

In your code it makes sense for there to be a call to an address in a register. Calling pA->show() requires a look up to see what the right function to be called is. This is because it is a virtual function on class A.

这篇关于将星星放在寄存器前是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆