1 / 14

CSC 3315 Subprograms: an Example

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 ;

aram
Download Presentation

CSC 3315 Subprograms: an Example

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. CSC 3315Subprograms: an Example HamidHarroud School of Science and Engineering, Akhawayn University http://www.aui.ma/~H.Harroud/csc3315/

  2. 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)

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

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

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

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

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

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

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

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

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

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

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

  14. Scope of Variables (Static 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) F1 (lien statique) (adresse retour) Main A 2 B 7 F2 F1 F1 Q L6m B 11 F3 F2 F2 R L3Q A 16 F4 F3 F1 P L3R

More Related