Computer Science 301 - 2006

Tutorial for week 20 - Stack Machine Code, T-diagrams

(a) Develop stack machine code equivalents of the following simple programs:

     (1)  void main () {
            for (int i = 0; i <= 10; i++) write(i, "\n")
          }

     (2)  void main () {
            int i = 0;
            int[] list = new int[11];
            while (i <= 10) {
              list[i] = 2 * i;
              i++;
            }
          }

     (3)  void main () {
            int[] list = new int[100];
            int i, j;
            read(i, j, list[i+j]);
            list[list[j]] = list[j + 2 * i];
          }

(b) Consider the following general form of T diagram. Although it uses the letters A through I in the various arms of the Ts, one could draw the diagram with fewer letters. How and why?

      .--------------------------.          .--------------------------.
      |                          |          |                          |
      |   A    ---------->  B    |          |   C   ----------->    D  |
      |                          |          |                          |
      `-------.          .--------------------------.          .-------'
              |          |                          |          |
              |     E    |    F   -------->     G   |     H    |
              |          |                          |          |
              `------------------.          .------------------'
                                 |          |
                                 |     I    |
                                 |          |
                                 `----------'

(c) In the practical sessions you should have used the Extacy Modula-2 to C translator. This was developed in Russia by a team who used the JPI Modula-2 compiler available for the PC. But the demonstration system we downloaded from the Internet came with the file XC.EXE, and a few other modules written in Modula- 2 (but not the source of the XC.EXE executable itself). Draw T-diagrams showing the process the Russians must have used to produce this system, and go on to draw T-diagrams showing how you managed to take the program SIEVE.MOD and run it on the PC using the Borland C++ system as your compiler of choice.


Home  © P.D. Terry