Assignment 5, Solved

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

 

  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?

    The assembler also supports & (bitwise and) and | (bitwise or). These are well defined for integers, but neither the and nor the or operator makes any sense with relocatable operands, so it would seem best to simply forbid relocation of either operand.

  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. this is a test

    That is, each word of the parameter list to the script is listed on a separate line.

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

    The script uses recursion in order to iterate through the parameter list. With each call, if there is a parameter present, it is output, and then, if there are any more parameters, they are passed on to the next recursive call (minus the first one).

  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?

    The suggested service in the text returns a pointer to the start of the loade code, allowing a later call to that code. The Unix service loads the new code and then immediately runs it, without allowing the caller any chance to intervene between loading and running the new code.

    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?

    The Unix service makes no provision for returning control from the loaded program to the caller!