1 / 13

More SIMPLESEM Examples

More SIMPLESEM Examples. CSCI 169 - Oleg Aulov A. Bellaachia. Review. Semantics SIMPLESEM C1 - simple statements only. C2 and C2’ - simple routines. Global data Routine declarations and definitions Main() routine C2’ - separate compilation. C2 - program example. int i=1,j=2,k=3;

butch
Télécharger la présentation

More SIMPLESEM Examples

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. More SIMPLESEM Examples CSCI 169 - Oleg Aulov A. Bellaachia

  2. Review • Semantics • SIMPLESEM • C1 - simple statements only

  3. C2 and C2’ - simple routines • Global data • Routine declarations and definitions • Main() routine • C2’ - separate compilation

  4. C2 - program example int i=1,j=2,k=3; alpha() { int i=4,l=5; … i+=k+l; … }; beta() { int k=6; … i=j+k; alpha(); … }; main() { … beta(); … }

  5. C3 - recursive functions • Direct recursion • Indirect recursion

  6. C3 - implimentation needs • Base address (known at exec time only) • LIFO stack • Return pointer • Dynamic link / dynamic chain

  7. C3 - program example int n; int fact() { int loc; if(n>1){ loc=n--; return loc * fact(); } else return 1; } main() { get(n); if(n>=0) print(fact()); else print(“input error”); }

  8. Show Examples Show Examples on a SIMPLESEM

  9. Example of C2 0 set 0,read 1 set 1,read 2 set 2,read 3 set 6,5 4 jump 10 5 halt 6 set 4,4 7 set 5,5 8 set 4, D[4]+D[2]+D[5] 9 jump D[3] 10 set 7,6 11 set 0, D[1]+D[7] 12 set 3, 14 13 jump 6 14 jump D[6]

  10. Example of C3 14 set D[0] + 2, D[2] 15 set 2, D[2] - 1 16 set 1, D[1] + 1 17 set D[1], ip + 4 18 set D[1] + 1, D[0] 19 set 0, D[1] 20 set 1, D[1] + 3 21 jump 13 22 set D[0] - 1, D[D[0] + 2] * D[D[1] - 1] 23 jump 25 24 set D[0] - 1, 1 25 set 1, D[0] 26 set 0, D[D[0] + 1] 27 jump D[D[1]] 0 set 1,3 1 set 2, read 2 jumpt 11, D[2] < 0 3 set 1, D[1] + 1 4 set D[1], ip + 4 5 set D[1] + 1, D[0] 6 set 0, D[1] 7 set 1, D[1] + 3 8 jump 13 9 set write, D[D[1] - 1] 10 jump 12 11 set write, "input error" 12 halt 13 jumpt 24, D[2] <= 1

More Related