Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inheritance CNS 4490. Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b.

Similar presentations


Presentation on theme: "Inheritance CNS 4490. Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b."— Presentation transcript:

1 Inheritance CNS 4490

2 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); }

3 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } bob.b bob.a ctrl link ret addr Activation record for main bp

4 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } Activation record for main Activation record for constructor bob.b bob.a ctrl link ret addr bp ctrl link this ptr b1 a1 ret addr bp

5 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } Activation record for main Activation record for two bob.b bob.a ctrl link ret addr bp ctrl link this ptr b1 a1 ret addr bp ctrl link this ptr a1 ret addr bp Activation record for one

6 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } bob.b bob.a ctrl link ret addr bp ctrl link this ptr b1 a1 ret addr bp push done1 ; ret addr push 3 ; a1 push 4 ; b1 push bp ; this ptr push bp ; ctrl link mov bp,sp ; setup bp jmp two@two done1: main: two@two: ctrl link this ptr a1 ret addr bp

7 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } bob.b bob.a ctrl link ret addr bp ctrl link this ptr b1 a1 ret addr bp push done1 ; ret addr push 3 ; a1 push 4 ; b1 push bp ; this ptr push bp ; ctrl link mov bp,sp ; setup bp jmp two@two done1: main: two@two: ctrl link this ptr a1 ret addr bp push done2 ;ret addr push [bp-16] ;a1 push bp-4 ; this ptr push bp ; ctrl link mov bp,sp jmp one@one done2: mov r1, [bp-8] ;this ptr push r1+4 ;&b push [bp-12] ; b1 pop r2 pop r1 mov [r1], r2

8 Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b = b1;} } class three { void main( ) { two bob(4,3); bob.fun( ); } bob.b bob.a ctrl link ret addr bp ctrl link this ptr b1 a1 ret addr bp push done1 ; ret addr push 3 ; a1 push 4 ; b1 push bp ; this ptr push bp ; ctrl link mov bp,sp ; setup bp jmp two@two done1: main: mov r1,[bp-8] ; this ptr push r1+0 ; &a push [bp-12] ; a1 pop r2 pop r1 mov [r1], r2 ; a = a1 sub sp, 12 ; clean up stack ret ; return ctrl link this ptr a1 ret addr bp one@one


Download ppt "Inheritance CNS 4490. Example class one { int a; one(int a1) {a = a1;} } class two : one { int b; int fun ( ) {b = a;} two(int a1,int b1) :base(a1){b."

Similar presentations


Ads by Google