What is the point of putting a star before registration?

I am learning how C ++ calls the correct member functions through assembly language. The simple program I came with is as follows:

class A { public: virtual void show() {} }; class B : public A { public: void show() {} }; int main() { A* pA = new B; pA->show(); return 0; } 

its assembly is as follows:

 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 

my questions:

  • I searched google for nwm, it only tells me that C ++ uses it to allocate memory, can someone tell me more about this? is it in one library? if possible, can i get its source code? as?
  • I'm not quite familiar with this syntax, what does he want to do?
+8
assembly
source share
1 answer

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

From the GNU as manual:

AT & T absolute (unlike PC) jump / call operands have the prefix `* '; they are not excluded in Intel Syntax.

In your code, it makes sense to refer to the address in the register. Calling pA->show() requires a search to see that the correct function must be called. This is because it is a virtual function of class A.

+11
source share

All Articles