1 / 14

Virtual

Virtual. CNS 4490. Example. class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) {

medea
Download Presentation

Virtual

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Virtual CNS 4490

  2. Example class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; d c bob joe ctrl link ret addr bp

  3. a vtable Example class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; d c bob joe ctrl link ret addr bp one@times

  4. b a vtable a vtable Example class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; d c bob joe ctrl link ret addr two@times bp one@times

  5. b a vtable a vtable Example class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk this retaddr retval d c bob joe ctrl link ret addr two@times bp one@times

  6. b a vtable a vtable Example class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk this retaddr retval bp ctrl lnk this retaddr retval d c bob joe ctrl link ret addr two@times bp one@times

  7. a vtable Example :One@One … :One@times … :Three@main ; alloc space for joe mov intreg, bp mov r50, 8 int 41 ;int vector for alloc ; setup vtable mov intreg, [bp] mov r50,4 int 41 mov r1,[bp] ; mov [r1], One@times; class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk this retaddr retval d c bob joe ctrl link ret addr bp one@times

  8. a vtable Example :One@One … :Three@main ;set up call to Construtor push done1 push [bp] push 4 push bp mov bp,sp jmp One@One :done1 class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk a1 this retaddr d c bob joe ctrl link ret addr bp one@times

  9. a vtable Example :One@One mov r1,this add r1,4 mov [r1],[bp-8] pop bp sub sp,8 ret … :Three@main :done1 class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk a1 this retaddr d c bob joe ctrl link ret addr bp one@times

  10. b a vtable a vtable Example :Three@main … ; alloc space for bob mov intreg, bp mov r50, 12 int 41 ;int vector for alloc ; setup vtable mov intreg, [bp] mov r50,4 int 41 mov r1,[bp] ; mov [r1], Two@times; class Two : One { int b; Two(int a1,int b1):One(a1) {b=b1;} override int times() {return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; d c bob joe ctrl link ret addr Two@times bp One@times

  11. b a vtable a vtable Example :Two@Two … :Three@main … ;set up call to Construtor push done2 push [bp+4] push 5 push 3 push bp mov bp,sp jmp Two@Two :done2 class Two : One { int b; Two(int a1,int b1):One(a1) {b=b1;} override int times() {return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk b1 a1 this retaddr d c bob joe ctrl link ret addr Two@times bp One@times

  12. b a vtable a vtable Example :Two@Two :;set up call to One@One push done3 push [bp-16] push [bp-12] push bp mov bp,sp jmp One@One :done3 ;Do Assignment mov r1,[bp-16] mov r1,[r1+8] mov r2, [bp-8] mov [r1], r2 … ret bp ctrl lnk a1 this retaddr class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk b1 a1 this retaddr d c bob joe ctrl link ret addr Two@times bp One@times

  13. b a vtable a vtable Example :Three@main … ;set up call to two@times push 0 push done4 push [bp+4] push bp mov bp,sp mov r1,[bp+4] jmp [r1] :done4 class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk this retaddr retval d c bob joe ctrl link ret addr Two@times bp One@times

  14. b a vtable a vtable Example :two@times mov r1,[bp-8] push [r1+8] push [r1+4] pop r2 pop r1 mul r1,r2 push r1 mov r1, bp-16 pop r2 mov [r1],r2 … ret class One { int a; One(int a1){a = a1;} int geta(){return a;} virtual int times(){return 2*a;} }; class Two : One { int b; Two(int a1,int b1):One(a1){b=b1;} override int times(){return b*a;} }; class Three{ void main( ) { One * joe = new One(4); One * bob = new Two(5,3); int c = bob.times( ); int d = joe.times(); } }; bp ctrl lnk this retaddr retval d c bob joe ctrl link ret addr Two@times bp One@times

More Related