Virtual
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

Virtual PowerPoint PPT Presentation


  • 73 Views
  • Uploaded on
  • Presentation posted in: General

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( ) {

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Virtual

Virtual

CNS 4490


Example

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


Example1

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

[email protected]


Example2

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

[email protected]

bp

[email protected]


Example3

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

[email protected]

bp

[email protected]


Example4

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

[email protected]

bp

[email protected]


Example5

a

vtable

Example

:[email protected]

:[email protected]

:[email protected]

; 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], [email protected];

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

[email protected]


Example6

a

vtable

Example

:[email protected]

:[email protected]

;set up call to Construtor

push done1

push [bp]

push 4

push bp

mov bp,sp

jmp [email protected]

: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

[email protected]


Example7

a

vtable

Example

:[email protected]

mov r1,this

add r1,4

mov [r1],[bp-8]

pop bp

sub sp,8

ret

:[email protected]

: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

[email protected]


Example8

b

a

vtable

a

vtable

Example

:[email protected]

; 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], [email protected];

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

[email protected]

bp

[email protected]


Example9

b

a

vtable

a

vtable

Example

:[email protected]

:[email protected]

;set up call to Construtor

push done2

push [bp+4]

push 5

push 3

push bp

mov bp,sp

jmp [email protected]

: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

[email protected]

bp

[email protected]


Example10

b

a

vtable

a

vtable

Example

:[email protected]

:;set up call to [email protected]

push done3

push [bp-16]

push [bp-12]

push bp

mov bp,sp

jmp [email protected]

: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

[email protected]

bp

[email protected]


Example11

b

a

vtable

a

vtable

Example

:[email protected]

;set up call to [email protected]

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

[email protected]

bp

[email protected]


Example12

b

a

vtable

a

vtable

Example

:[email protected]

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

[email protected]

bp

[email protected]


  • Login