Assignment 5, due Sept 29

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

Notice: Midterm Exam I is Friday Oct 3

Machine Problem II Due Oct. 8

Implement the LOOP and ENDLOOP primitives suggested at the end of Chapter 6 of the notes. Boolean expressions shold be allowed (but optional) as operands on both the LOOP and ENDLOOP directives. If the expression on LOOP is present and evaluates to false, the loop will terminate. If the expression on ENDLOOP is present and true, the loop will terminate. Demonstrate your program with a loop that builds a table of the first 20 squares, using the recurrence relation that one squared is one and (n+1)2 is n2+n+n+1 (this allows you to generate a table of squares without the need to use a multiply operator, something that is missing from EAL).

Homework Due Sept 29

  1. Do Chapter 6 Problem 1 from the notes.

  2. The standard C library contains an interesting input-output primitive, fseek(). (There are also a number of related primitives that offer alternative and simplified user interfaces, but all of the functionality of these can be obtained from fseek() with appropriate parameters.)

    Look up fseek() in the Unix programmer's reference manual (the on-line man command) or in The C Programming Language, Second Edition by Kernighan and Ritchie, and then describe how this primitive could be used in the implementation of the LOOP and ENDLOOP assembly directives illustrated in Figure 6.18.

  3. Now, consider the problem of implementing nested LOOP ENDLOOP blocks, where loops may be either within the body of a macro or outside any macro. A stack is involved, so you can use the macro expansion stack. What would you push on the stack when you encounter a LOOP directive and pop when you encounter an ENDLOOP directive? Give enough detail to demonstrate that you know how this differs depending on where the loop is (in a macro versus in a regular source file).

  4. Do problem 2 from chapter 7 of the notes.