class B {
public:
int b1;
int b2;
};
class D : public B {
public:
int d1;
int d2;
};
D *d = new D ();
d->d1 = 9032;
d->d2 = 3293;
d->b1 = 2948;
d->b2 = 8432;
B *b = d;
int x1 = b->b1;
int x2 = b->b2;
|
|
; d->d1 = 9032;
movq -8(%rbp), %rax ; load d into rax, at -8 bytes off of base pointer
movl $9032, 8(%rax) ; write 9032 into d1, at 8 bytes off of rax
; d->d2 = 3293;
movq -8(%rbp), %rax ; load d into rax
movl $3293, 12(%rax) ; write 3293 into d2, at 12 bytes off of rax
; d->b1 = 2948;
movq -8(%rbp), %rax ; load d into rax
movl $2948, (%rax) ; write 2948 into b1, at 0 bytes off of rax
; d->b2 = 8432;
movq -8(%rbp), %rax ; load d into rax
movl $8432, 4(%rax) ; write 8432 into b2, at 4 bytes off of rax
; B *b = d;
movq -8(%rbp), %rax ; load d into rax
movq %rax, -16(%rbp) ; copy rax=d into b, at -16 bytes off of base pointer
; int x1 = b->b1;
movq -16(%rbp), %rax ; load b into rax
movl (%rax), %eax ; load b1, at 0 bytes off of rax, into eax
movl %eax, -20(%rbp) ; load eax into x1, at -20 bytes off of base pointer
; int x2 = b->b2;
movq -16(%rbp), %rax ; load b into rax
movl 4(%rax), %eax ; load b2, at 4 bytes off of rax, into eax
movl %eax, -24(%rbp) ; load eax into x2, at -24 bytes off of base pointer
|
|
|
Layout of Stack
|
|
Offset
|
Contents
|
|
-8(%rbp)
|
local variable D *d
|
|
-16(%rbp)
|
local variable B *b
|
|
-20(%rbp)
|
local variable int x1
|
|
-24(%rbp)
|
local variable int x2
|
|
Layout of Instance of D
|
|
Offset
|
Name
|
Contents
|
| 12 | d2 | 3293 |
| 8 | d1 | 9032 |
| 4 | b2 | 8432 |
| 0 | b1 | 2948 |
|