# CSC3315 (Spring 2009)1 CSC 3315 Subprograms: an Example Hamid Harroud School of Science and Engineering, Akhawayn University

## Presentation on theme: "CSC3315 (Spring 2009)1 CSC 3315 Subprograms: an Example Hamid Harroud School of Science and Engineering, Akhawayn University"— Presentation transcript:

CSC3315 (Spring 2009)1 CSC 3315 Subprograms: an Example Hamid Harroud School of Science and Engineering, Akhawayn University http://www.aui.ma/~H.Harroud/csc3315/

program Main; var A, B: integer; procedure P; begin {P} {L1P} A := A + 1; {L2P} B := B + 1; {L3P} end; procedure Q; var B: integer; procedure R; var A: integer; begin {R} {L1R} A := 16; {L2R} P; {L3R} write(A, B); {L4R} end; {continued} begin {Q} {L1Q} B := 11; {L2Q} R; {L3Q} P; {L4Q} write(A, B); {L5Q} end; begin {Main} {L1m} A := 1; {L2m} B := 6; {L3m} P; {L4m} write(A, B); {L5m} Q; {L6m} write(A, B); {L7m} end. An Example (in Pascal)

(dynamic link) (static link) (return address) A 1 B 6 F1 L4m F1 F2 Main P situation just after a call to P is made: IP = L1P, EP = F2

(dynamic link) (static link) (return address) A 2 B 7 situation after a call to P in Main is terminated: IP = L4m, EP = F1 F1 Main

(dynamic link) (static link) (return address) A 2 B 7 F1 L6m B F1 F2 Main Q situation just after a call to Q in Main is made: IP = L1Q, EP = F2

6) (dynamic link) (static link) (return address) A 2 B 7 F1 L6m B 11 F2 L3Q A F1 F2 F3 Main Q R Situation just after a call to R in Q in Main is made: IP = L1R, EP = F3

(dynamic link) (static link) (return address) A 2 B 7 F1 L6m B 11 F2 L3Q A 16 F3 F1 L3R F1 F2 F3 F4 Main Q R P situation just after a call to P in R in Q in Main is made: IP = L1P, EP = F4

(dynamic link) (static link) (return address) A 3 B 8 F1 L6m B 11 F2 L3Q A 16 F1 F2 F3 Main Q R situation after a call to P in R in Q in Main is terminated: IP = L4R, EP = F3

(dynamic link) (static link) (return address) A 3 B 8 F1 L6m B 11 F1 F2 Main Q situation after a call to P in Q in Main is terminated: IP = L3Q, EP = F2

(10) (dynamic link) (static link) (return address) A 3 B 8 F1 L6m B 11 F2 F1 L4Q F1 F2 F3 Main Q P situation just after a call to P in Q in Main is made: IP = L1P, EP = F3

(dynamic link) (static link) (return address) A 4 B 9 F1 L6m B 11 F1 F2 Main Q situation after a call to P in Q in Main is terminated: IP = L4Q, EP = F2

(dynamic link) (static link) (return address) A 4 B 9 situation after a call to Q in Main is terminated: IP = L6m, EP = F1 F1 Main

In case Q in Main is called: Main.Q.B(0, 3) Main.A(1, 3) Main.Bhidden (dynamic link) (static link) (return address) A 2 B 7 F1 L6m B F1 F2 Main Q Scope of Variables (Static link)

In case P in R in Q in Main is called: Main.Q.R.Ahidden Main.Q.Bhidden Main.A(1, 3) Main.B(1, 4) (lien dynamique) (lien statique) (adresse retour) A 2 B 7 F1 L6m B 11 F2 L3Q A 16 F3 F1 L3R F1 F2 F3 F4 Main Q R P Scope of Variables (Static link)

Download ppt "CSC3315 (Spring 2009)1 CSC 3315 Subprograms: an Example Hamid Harroud School of Science and Engineering, Akhawayn University"

Similar presentations