Refer to this article: http://blog.csdn.net/linyt/article/details/6336762
classBase { Public: Virtual voidf () {}Virtual voidg () {}}; classDerive: PublicBase { Public: Virtual voidf () {}}; intMain () {Derive D; intA =4; Base*PB; intb =5; PB= &D; intc =6; PB-f (); return 0; }
%ESP| ...| | | ------>Derive d| | | ------>int C| | | ------>base *PB| | | ------>int b| | | ------>int a| +
. file"main.cpp". Section. Text$_zn4base1fev,"x". linkonce Discard. Align2. Globl __zn4base1fev. def __zn4base1fev;. SCL 2; . type 32; . Endef__zn4base1fev:LFB0:. Cfi_startproc pushl%ebp. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%ebp. Cfi_def_cfa_register5Subl $4,%esp movl%ecx,-4(%EBP)Leave. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE0:. Section. Text$_zn4base1gev,"x". linkonce Discard. Align2. Globl __zn4base1gev. def __zn4base1gev;. SCL 2; . type 32; . Endef__zn4base1gev:LFB1:. Cfi_startproc pushl%ebp. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%ebp. Cfi_def_cfa_register5Subl $4,%esp movl%ecx,-4(%EBP)Leave. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE1:. Section. Text$_zn6derive1fev,"x". linkonce Discard. Align2. Globl __zn6derive1fev. def __zn6derive1fev;. SCL 2; . type 32; . Endef__zn6derive1fev:LFB2:. Cfi_startproc pushl%ebp. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%ebp. Cfi_def_cfa_register5Subl $4,%esp movl%ecx,-4(%EBP)Leave. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE2:. Section. Text$_zn4basec2ev,"x". linkonce Discard. Align2. Globl __zn4basec2ev. def __zn4basec2ev;. SCL 2; . type 32; . Endef__zn4basec2ev://105, come on .LFB6:. Cfi_startproc pushl%ebp. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%ebp. Cfi_def_cfa_register5Subl $4,%ESP//Allocate 4 bytes of space on the stack movl%ecx,-4(%EBP)//Copy the address of D to the 4-byte space allocated in the previous step MOVL-4(%EBP),%eax//Copy this value to%eax movl $__ztv4base+8, (%EAX)//Copy the vtable start address of base to the stack referred to by%EAX, which is the space of DLeave//Return, how did not restore%EBP and%esp ah. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE6:. Section. Text$_zn6derivec1ev,"x". linkonce Discard. Align2. Globl __zn6derivec1ev. def __zn6derivec1ev;. SCL 2; . type 32; . Endef__zn6derivec1ev://131, come on .LFB9:. Cfi_startproc PUSHL%EBP//Save%EBP to the top of the stack. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%EBP//Save%esp. Cfi_def_cfa_register5Subl $4,%ESP//Allocate 4 bytes of space on the stack movl%ecx,-4(%EBP)//Copy the address of D to the 4-byte space allocated in the previous step, use Movl%ecx,%esp should be OK MOVL-4(%EBP),%eax//Copy this value to%eax movl%eax,%ECX//And then copy this value to%ECX, for the fur cuff over the pastPager__zn4basec2ev//initialize base, see line 70 MOVL-4(%EBP),%eax//Copy the address of D to%eax MOVL $__ztv6derive+8, (%EAX)//Copy the derive's vtable start address to D space, which overwrites the copy work done by the previous step baseLeave. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE9:. def ___main;. SCL 2; . type 32; . Endef. Text. GLOBL _main def _main;. SCL 2; . type 32; . Endef_main:LFB3:. Cfi_startproc pushl%ebp. Cfi_def_cfa_offset8. Cfi_offset5, -8movl%esp,%EBP//save stack frame, main returns when useful. Cfi_def_cfa_register5Andl $- -,%ESP//will%esp four bits after zeroing, moving toward the stack growth direction, for memory alignment SUBL $ +,%ESP//allocated 32 bytes of spacePager___main//Call main function Leal A(%ESP),%eax//Copy the address of derive D to%eax movl%eax,%ecx//copy%eax to%ECX, remembering that%ECX stores the address of D at this timePager__zn6derivec1ev//Initialize D, line 93rd MOVL $4, -(%ESP)//intA =4MOVL $5, -(%ESP)//intb =5Leal A(%ESP),%eax//Copy the address of D to%eax Movl%eax, -(%esp)//*PB = &d MOVL $6, -(%ESP)//intc =6MOVL -(%ESP),%eax//To copy the PB value that is the address of D to%eax MOVL (%eax),%EAX//will be the value of D, that is vtable copy to%eax MOVL (%eax),%eax Take the value of the first byte of vtable (derive), which is the address of method F, copied to%eax MOVL -(%ESP),%edx//The address of PB is copied to%edx movl%edx,%ecx//ecx the address of D is stored at this timePager*%eax//Call derive F function Movl $0,%eaxLeave. Cfi_restore5. CFI_DEF_CFA4,4 ret. Cfi_endprocLFE3:. Globl __ztv6derive. Rdata$_ztv6derive,"Dr". linkonce same_size. Align8__ztv6derive:. Long0. Long __zti6derive. Long __zn6derive1fev//+8 Here the method that points to the subclass. Long __zn4base1gev//still points to the parent The method of the class. Globl __ztv4base. Section. Rdata$_ztv4base,"Dr". linkonce same_size. Align8__ztv4base:. Long0//+0. Long __zti4base//+4. Long __zn4base1fev//+8This is the address where base vtable begins. Long __zn4base1gev. Globl __zts6derive. Rdata$_zts6derive,"Dr". Linkonce same_size__zts6derive:. ASCII"6derive\0". Globl __zti6derive. Rdata$_zti6derive,"Dr". linkonce same_size. Align4__zti6derive:. Long __ztvn10__cxxabiv120__si_class_type_infoe+8. Long __zts6derive. __zti4base. globl __zts4base. Section. Rdata$_zts4base,"Dr". Linkonce same_size__zts4base:. ASCII"4base\0". Globl __zti4base. Rdata$_zti4base,"Dr". linkonce same_size. Align4__zti4base:. Long __ztvn10__cxxabiv117__class_type_infoe+8. Long __zts4base. Ident"GCC: (GNU) 4.9.3"
C + + virtual function compilation