Assignment 5, due June 23

Machine Problem 2, due June 28

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

Machine Problem 2, due June 28

Modifications to EAL

Create a working directory called mp2, and then either: Install the source code from

http://homepage.cs.uiowa.edu/~dwjones/syssoft/hw/mp0.txt
Or make a copy of your solution to MP1 to this directory and continue development here, so you end up with all your solutions integrated into one program.

Having done this, note that the assembler, as currently configured, supports only the following forms of expressions, as documented in the header comments of parse_operand in parser.c:

<term> ::= <identifier> | <number> | .
<operand> ::= <term> { (+|-|&||) <term> }

Modify the code so it supports and evaluates expressions with the following grammar:

<term> ::= <identifier> | <number> | . | ( <operand> )
<sub expression> ::= <term> { (+|-|&||) <term> }
<operand> ::= <sub expression> [ = <sub expression> ]

Note that there are two distinct changes here: First, we allow parentheses, such as a-(b&c), and second, we allow a comparison operator, and equals-to. The comparison operator has a lower precidence than arithmetic, so a+b=c+d is equivalent to (a+b)=(c+d) and is definitely not equivalent to a+(b=c)+d. Comparison should produce zero for false and all ones for true (all ones is FFFF16).

Make sure your modified version of EAL claims to be written by you and that it claims to be a solution to MP2 (by default, it claimed to be MP0). These are settings in the Makefile.

Make sure that all of your code conforms to the style guidelines

http://homepage.cs.uiowa.edu/~dwjones/syssoft/style.html
Pay close attention to indenting (depending on how you downloaded your code, tab-to-space conversion may have seriously damaged the indenting), and pay close attention to the commenting rules for documenting revisions. Specifically, use comments of the form /*MP1*/ to mark any line you added, and add an appropriate revision line to the header block of any file you change.

Testing

Write an EAL program that thoroughly tests your modified code, specifically, this should demonstrate all of the operators supported by the expression package, it should demonstrate all operator precidence relationships and the effect of parenthesizing expressions. This expression grammar offers an infinite range of

Comments and organization in test files are just as important as they are in the programs they test, so your test data should be well documented! Comments in the test data should document what is being tested and what the expected results of the test are.

Turn in

Paper listings of every file from the EAL source code that you changed (obviously, parser.c will be one of these). and a paper listing of the listing file produced by EAL when it processes your test data.

Assignment 5, due June 23

  1. Do problem 12 in Chapter 5, but assume this instruction set:
    PUSHI i
    pushes the integer constant i on the stack.
    LOAD
    pops an address a off the stack and then pushes the contents of memory location a.
    ADD
    SUB
    MUL
    DIV
    each of these pops two values off the stack and then does the indicated arithmetic operation.

  2. The C and C++ preprocessors support macro definition using this notation:
    #define plus(a,b) a + b
    

    If, in the body of the program, someone wrote

    i = plus(i,1);
    

    The result would be

    i = i + 1;
    
    Write a set of macros that allow a C programmer to write code in this horrible notation:
    assign(i,times(plus(i,1),times(j,2)));
    

    This should end up having a meaning something like this:

    i = (i + 1) * (j * 2);
    

    Note, you may need to use more parentheses.

  3. The fictional Ultimate RISC computer has one machine instruction, move, which moves an operand from the source address to the destination address. What the programmer wants to be able to write for this instruction is:
    	MOVE src,dst
    

    The result should be identical to having written this:

    	W    src
    	W    dst
    
    Write a macro, using the macro notation presented in Chapter 6, that will produce this result.