Assignment 2 solution

Part of the homework for 22C:50, Summer 2004
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. To prove that you've done this: Change the AUTHOR line in the Makefile so it gives your name, and then run make and run the application using the -help option and capture the output it gives (screen shot, script file, any form of capture will do, even a handwritten copy of the output), and turn that in with your solutions to this assignment. Do not turn in a listing of any of the C source files that make up the assembler!
    	% eal -help
    	eal <infile> [-l <listfile>] [-d]
    	   assemble EAL code from <infile>,
    	   listing directed to to <listfile> (defaults to <basefile>.l),
    	   where <infile> = <basefile>.<suffix>;
    	   -d adds symbol table to listing.
    
    	   EAL V0.0 by Douglas W. Jones.
    	% 
    

  2. a) Assemble the above code using the the EAL assembler you got for problem 1. Turn in the assembly listing file -- the assembler's output from assembling this input.
    	EAL V0.0 by Douglas W. Jones; Fri Jun 11 14:49:53 2004
    
    	     1             |NULL    =       0
    	     2             |
    	     3 0000: 0000  |A:      W       NULL    ; left
    	     4 0002: 0000  |        W       NULL    ; right
    	     5 0004: 01    |        B       1       ; data
    	     6             |
    	     7 0005: 0000  |B:      W       A
    	     8 0007: 0000  |        W       NULL
    	     9 0009: 02    |        B       2
    	    10             |
    	    11 000A: 0000  |C:      W       NULL
    	    12 000C: 0000  |        W       NULL
    	    13 000E: 04    |        B       4
    	    14             |
    	    15 000F: 0005  |D:      W       B
    	    16 0011: 0014  |        W       E
    	    17 0013: 03    |        B       3
    	    18             |
    	    19 0014: 000A  |E:      W       C
    	    20 0016: 0000  |        W       NULL
    	    21 0018: 05    |        B       5
    

    b) This code describes a binary tree with nodes named A through E. draw that tree in graphical form, showing, in each node, the node name and the data stored there. Identify the root!

    	         D  --- the root
    	        /3\
    	       /   \
    	      B     E
    	     /2\   /5\
    	    A     C
    	   /1\   /4\
    	  
    

    c) There is something wrong with this tree that isn't visible in the assembly code but is obvious if you read the assembly listing showing the result of this assembly. What is the problem?

    It will be difficult to distinguish between a pointer to the root and a null pointer, since both will be represented as 000016.

  3. The part of the EAL grammar given in figures 2.9 and 2.10 (using two different formal notations) does not entirely agree with the grammar parsed by the EAL assembler. In the file parser.c, there are differences in parse_definition() and parse_line()

    a) Looking only at syntax issues and ignoring the added code for graceful error handling, what is the difference between parse_definition() and the grammar from the notes?

    In Figures 2.9 and 2.10, there is only one form of definition, <identifier>=<operand>. In parse_definition there is an additional form, .=<operand>.

    b) Again, looking only at syntax issues, and not at semantics, what is the difference between parse_line() and the notes?

    In Figures 2.9 and 2.10, comments are handled in the syntax for <line>. In parse_line there is nothing to handle comments because this issue was handled in the lexical analyzer.