120 likes | 325 Views
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 {
E N D
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 { 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
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
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
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:
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:
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
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:
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:
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
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