Assignment 5, due July 2

Includes Machine Problem 3, due July 7

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

 

Machine Problem 3

Ground rules: The ground rules distributed with MP1 hold for this assignment, with the exception that you may base your solution on the distributed soultion to MP1:

http://homepage.cs.uiowa.edu/~dwjones/syssoft/hw/mp1.txt

If you wish, you may base your solution to this problem on your solution to MP1 or MP2, but please note the way changes are documented in the posted solution!

The assignment: The assembler, as distributed, only supports absolute assembly. Add support for relocation. Specifically, the location counter should start out relocatable, and all integer constants are absolute, as described in the lecture notes. To do this, you will need to do the following:

  1. Add a new attribute to the defined type OBJECT_VALUE.
  2. Make sure this attribute is set correctly whenever assignments are made to variables of type OBJECT_VALUE. Sometimes this will involve no change, sometimes it will involve added code; you will have to look at and understand the context to figure this out.
  3. Make sure the assembly listing correctly reports for all values being printed whether those values are absolute or relocatable. Use the notation we used in lectures (a trailing + after a value to indicate that it is relocatable).
  4. Make the B directive forbid relocatable bytes, since relocation only applies to addresses, and a byte cannot hold an address.

Unlike the previous 2 machine problems, this one is not localized to just one part of the assembler! It requires making a modest number of very small changes that are dispersed through the code. You will find that the Unix grep utility is quite handy, for example, to find all source or header files that hold uses of OBJECT_VALUE or to find all uses of some variable of this type.

Homework 5

  1. To do the machine problem, you will have to add code to parse_operand to propagate the absolute or relocatable status of values through expressions. In lecture and in the text (see Figure 7.6), rules were discussed for dealing with addition and subtraction. The assembler supports some other operators! How should relocatable operands be treated for each of these, and what is the type of the result?

  2. Consider the fillowing Unix shell script, stored in an executable file named scr:
    # scr
    if ( "$1" != "" ) then
    	echo $1
    	scr ${argv[2-]}
    endif
    
    Here is a call to this shell script:
    scr this is a test
    
    Part a: What output does this script produce under the tcsh shell? You may need to use the man command to look at the manual for tcsh, but of course, you can also try running the script.

    Part b: Explain the use of recursion in this script.

  3. Most modern versions of the Unix operating system really only offers one loader system service, execve(). Look up this service in the Unix Programmer's manual and, after reading about it, answer the following questions about differences between this and the loader system service suggested in Figure 8.5 and the accompanying text.

    Part a: The execve() service and the service suggested in the text differ in how control is transferred to the newly loaded program. What is the difference?

    Part b: The execve() service and the service suggested in the text differ in the provisions they make for returning control from the newly loaded program to the original program after the new one finishes. What is the difference?