Course  
  Menu  
  Course  
 Description 
  Course  
  Outline  
 Assignments 
 & Doc Specs 
  Software  
  Summary  
  Class  
  Notes  
 Pseudocode 
  Modules  
  SIC/XE  
  Reference  
 Course  
 Supplement 
CNW Home
Fall Term, 2006  .

Assignment #6

Programming exercises: Due by midnight on Sunday, November 26, 2006.

When memory is tight, pass 1 and pass 2 each do a sequential read of the source file to obtain sourcelines, processing them as they are input, and not retaining them. Since memory is not tight, this process can be simplified by simply reading the entire source file into an array of strings, then processing the source code from this array, taking full advantage of the indexing implicitly available in array processing. Part A of the assignment is to devise a getsource routine to bring a source file into memory, deleting any blank lines encountered in the process, and returning the number of lines stored in memory. Part B is to use the routines from the prior assignments in the construction of pass1 for an assembler.

  1. getsource specifications:
    Structures
    extern char sourcelist[][81];
    int getsource(filename)
      char filename[];
    
    Parameters: filename is the name of the source file.
    Assumptions:

    The library <stdio.h> should be included to provide standard I/O routines and the FILE data type.

    #include <stdio.h>
       . . .
    FILE *fptr;
       . . .
    fptr = fopen(filename,"r");
       . . . (for input from the file use fgets)
    fclose(fptr);
    
    sourcelist is an external array of strings to hold the input source code.
    The newline character that fgets automatically brings in with each line should be stripped.
    Lines consisting on nothing but "whitespace" should be purged.

    Returned Value:

    Return the number of source lines installed in sourcelist array. Return 0 if the file is empty. If the file does not exist, return 0 and print a message to that effect.
    File name:
    getsource.c

    Procedure:

    • Design and construct a getsource routine that conforms to the above specification. The external array sourcelist is best defined in main, since it will be used in both pass 1 and pass 2.
    • Devise a small driver to test your routine. Name the C source file for your driver <student-id>-6.A.driver.c.
    • Your driver simply needs to invoke getsource for some text file, then print out the sourcelist array to verify both removal of blank lines and accuracy of content.
    • The test plan is simple, but you will need to plan it for write up. In particular, your driver needs to produce a test log. Assuming that you utilize the hlib functions for this purpose, move hlib.log to a file named <student-id>-6.A.log for use in your Part A documentation in a manner analogous to that for prior assignments.

      You may or may not want to use a makefile for this part.

  2. pass1 specifications:
    Structures
    #ifndef SYMBSIZE
      #define SYMBSIZE 10
    #endif
    typedef struct tabinfo
      {
        int  val;
        int  type;
        int  info;
      } tabdata;
    typedef struct tablemem
      {
        char    symbol[SYMBSIZE];
        tabdata symbdata;
      } tabletype;
    /*
       extern references for routines to be linked in separately
    */
    extern char sourcelist[][81]; /* Holds source file input     */
                                  /*   under getsource           */
    extern int sourcecnt;         /* Number of lines of code     */
                                  /*   input by getsource        */
    extern int errors[];          /* Error list; errors[i] goes  */
                                  /*   with sourcelist[i]        */
    extern tabletype symbtab[];   /* The symbol table (as        */
                                  /*   processed by "insert")    */
    extern int symbtabsize;       /* The number of symbol table  */
                                  /*   entries                   */
    extern tabletype codetable[]; /* The op code table (as used  */
                                  /*   by the "incr" routines)   */
    extern int codetabsize;       /* The number of op code table */
                                  /*   entries                   */
    int pass1();

    Returned value:

    Return -1 if there are any pass 1 errors, otherwise the return value is to indicate where program excution is to begin. If there is an operand on the END statement, it gives this value. If not, then the START value is returned as a default.
    File name:
    pass1.c

    Procedure:

    • Using the modules from prior assignments (findlast, insert, breakup, opcodeincr, storageincr, getsource), devise a C function named pass1 to implement pass 1 for a SIC/XE assembler along the lines represented in the pseudocode module " Pass1 and Pass2" on the course web page.
    • The driver COP3601-6.o for this part of the assignment is in the assgn-6 subdirectory of the class directory. It provides means for testing your pass1 routine in the same manner as for prior assignments. The driver provides the external data storage indicated above, and will prompt for the name of the source file being used to test your code. It employs your getsource routine to bring the file in (to the sourcelist array).

      The array errors is a list of integers (initially all 0), with the same number of entries as the sourcelist array has rows. When an error is detected in sourcelist[i], your routine should assign an appropriate error code in errors[i]. Regardless of errors detected, your routine should process to the end of the source code (your overall assembler, however, may abort pass 2 in the face of pass 1 errors, going directly to the assembler report).

      If errors are detected, the driver exhibits the source line and the error code for each error found. The driver lists out the symbol table created by your routine, whether or not there are errors. If the return value is not -1, the returned value is also shown.

      The hlib functions are compiled into COP3601-6.o.

    • Devise a make file named <student-id>-6.makefile to compile your pass1 routine and link it with the supplied driver, executable named <student-id>-6. The basic command line needed for the driver is:
      cc COP3601-6.o pass1.o getsource.o -o <student-id>-6
      pass1.o should have all of your other ".o" modules linked into it. Your makefile should compile any ".o" modules not up to date.
    • Devise a test plan for your subroutine that uses the driver to fully exercise your subroutine. For your test plan, include the following as your first two test files:
      COP3601-6.t1
      COP3601-6.t2
      which are stored in the assgn-6 subdirectory of the class directory. In addition to these two test files, devise a test file named <student-id>-6.B.testfile that will test elements of your routine not handled by either of the above two test files. Do not just recycle a SIC/XE source file from earlier ... you need to justify what is in this file and why. Note that you are only testing pass 1, so the SIC/XE test program does not have to make sense. The fact that test files have a great deal of code that will not assemble should not prevent them from being processed by pass1. Make adjustments to your subroutines as necessary to correct for any problems presented by test cases.

      When you are satisfied that you have an effective test plan, remove hlib.log and then run your tests. When finished, move hlib.log to a file named <student-id>-6.B.log for use in your Part B documentation in a manner analogous to that for prior assignments.

Construct Word documentation as specified on the assignments page. Remember that your documentation file is to have 2 distinct parts, a write-up for Part A and a write-up for Part B, each with its own executive summary and set of appendices as noted above. Use the submit shell script from /usr/public/cop3601/cwinton to "shar" your

  • documentation (<student-id>-6.doc)
  • getsource source code (getsource.c)
  • pass1 source code (pass1.c)
  • Part B testfile (<student-id>-6.B.testfile)
  • Part B make file (<student-id>-6.makefile)
  • Part A log file (<student-id>-6.A.log)
  • Part B log file (<student-id>-6.B.log)
  • Part A driver (<student-id>-6.A.driver.c)
  • findlast source code (findlast.c)
  • insert source code (insert.c)
  • breakup source code (breakup.c)
  • opcodeincr source code (opcodeincr.c)
  • storageincr source code (storageincr.c)
and "turnin" by midnight on Sunday, November 26 to cnw.3601.6. Late submissions can be submitted until noon on Friday, December 8 via submit to cnw.3601.6L (late points assessed as stipulated on the assignments page).