csc3315 (spring 2009)1 csc 3315 subprograms: an example hamid harroud school of science and...
TRANSCRIPT
CSC3315 (Spring 2009) 1
CSC 3315CSC 3315Subprograms: an Subprograms: an ExampleExample
Hamid HarroudHamid HarroudSchool of Science and Engineering, Akhawayn School of Science and Engineering, Akhawayn
UniversityUniversityhttp://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)An Example (in Pascal)
(dynamic link)(static link)
(return address)A 1B 6
F1F1
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 2B 7
situation after a call to P in Main is terminated:
IP = L4m, EP = F1
F1
Main
(dynamic link)(static link)
(return address)A 2B 7
F1F1
L6mB
F1
F2
Main
Q situation just after a call to Q in Main is made:
IP = L1Q, EP = F2
6)6)(dynamic link)(static link)
(return address)A 2B 7
F1F1
L6mB 11
F2F2
L3QA
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 2B 7
F1F1
L6mB 11
F2F2
L3QA 16
F3F1
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 3B 8
F1F1
L6mB 11
F2F2
L3QA 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 3B 8
F1F1
L6mB 11
F1
F2
Main
Q situation after a call to P in Q in Main is terminated:
IP = L3Q, EP = F2
(10)(10)(dynamic link)(static link)
(return address)A 3B 8
F1F1
L6mB 11
F2F1
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 4B 9
F1F1
L6mB 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 4B 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.B hidden
(dynamic link)(static link)
(return address)A 2B 7
F1F1
L6mB
F1
F2
Main
Q
Scope of Variables (Static Scope of Variables (Static link)link)
In case P in R in Q in Main is called:
Main.Q.R.A hidden
Main.Q.B hidden
Main.A (1, 3)
Main.B (1, 4)
(lien dynamique)(lien statique)
(adresse retour)A 2B 7
F1F1
L6mB 11
F2F2
L3QA 16
F3F1
L3R
F1
F2
F3
F4
Main
Q
R
P
Scope of Variables (Static Scope of Variables (Static link)link)