1 / 12

Classes

Classes. CNS 4490. Example. class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } }. Example. class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two {

aderes
Download Presentation

Classes

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. Classes CNS 4490

  2. Example class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } }

  3. Example class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } setup call to constructor bob.a b ctrl link ret addr Activation record for main bp

  4. Example class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } setup call to constructor a1 this ptr ctrl link ret addr bp Activation record for constructor bob.a b ctrl link ret addr Activation record for main bp

  5. Example class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } setup call to constructor a1 this ptr ctrl link ret addr bp Activation record for constructor bob.a b ctrl link ret addr Activation record for main bp

  6. Example one@one: class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } a1 this ptr ctrl link ret addr bp main: push done ; ret addr push bp ; ctrl link mov r1, bp add r1, 4 mov bp,sp ; setup bp push r1 ; this ptr push 3 ; a1 jmp one@one bob.a b ctrl link ret addr bp done:

  7. Example one@one: mov r1, [bp +0] ; this ptr push [r1] ; & a mov r1, [bp + 4] push r1 ; a1 pop r2 pop r1; mov [r1], r2 ; assignment clean up stack class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } a1 this ptr ctrl link ret addr bp main: push done ; ret addr push bp ; ctrl link mov r1, bp add r1, 4 mov bp,sp ; setup bp push r1 ; this ptr push 3 ; a1 jmp one@one bob.a b ctrl link ret addr bp done:

  8. Example class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } setup call to geta this ptr ctrl link ret addr ret value bp Activation record for geta bob.a b ctrl link ret addr Activation record for main bp

  9. Example one@geta: class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } this ptr ctrl link ret addr ret value bp main: push 0 ; ret value push done ; ret addr push bp ; ctrl link mov r1, bp add r1, 4 mov bp,sp ; setup bp push r1 ; this ptr jmp one@geta bob.a b ctrl link ret addr bp done:

  10. Example one@geta: mov r1, [bp] ; &a mov r2, bp sub r2, 12 mov [r2], [r1] … clean up stack … class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } bp this ptr ctrl link ret addr ret value main: push 0 ; ret value push done ; ret addr push bp ; ctrl link mov r1, bp add r1, 4 mov bp,sp ; setup bp push r1 ; this ptr jmp one@geta bob.a b ctrl link ret addr bp done:

  11. Dot Operator class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } . bob geta What does the “.” operator do? In this instance it simply returns the bob@geta code address and looks up the geta function in the bob symbol table

  12. Symbol Tables class one { int a; int geta( ){ return a; } one(int a1) {a = a1;} } class two { void main( ) { int b; one bob(3); b = bob.geta( ); } } Main Symbol Table class one class two “one” Symbol Table int a int geta( ) one (int a1) “two” Symbol Table void main ( ) “main” Symbol Table int b one bob

More Related