Assignment 2, due Feb. 7 (date changed due to snow)

Part of the homework for 22C:112, Spring 2011
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID and on the class list! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what insurance companies call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!

  1. Background: Some machines have position independent code, where all branch and call instructions use PC-relative instructions. On such machines, no relocation is needed for such instructions, so it is potentiall possible to load a program in any addresses in memory.

    In a conventional linker, when memory location x is marked as a reference to label L, once the value of L is found during linking, the linker simply does M[x]=value(L) in order to link the instruciton to the label.

    a) If the reference to label L is in the context of a PC-relative branch or call instruction, how does th linker link the instruction to the label? (0.5 points)

    b) Position independent code allows the program's code to be loaded anywhere in memory without relocation. Does it give similar freedom with respect to the program's stack segment? (0.5 points)

    c) Position independent code allows the program's code to be loaded anywhere in memory without relocation. Does it give similar freedom with respect to the program's static segment? (0.5 points)

  2. Background: LaTeX is a text formatting system that is most useful for large documents such as books. The source for a LaTeX document generally consists of a large collection of files (typically all in one directory) with the file type indicated by the suffix. You might, for example, find:

    The following shell commands build (in the appropriate combination) book.pdf from all of the above, plus several intermediate files (simplified):

    In the above, some files are both read and written by the same shell command. In these cases, the original is read first, and then the replacement written.

    A Problem: Write a makefile to generate book.pdf. (There is no perfect answer because of the cyclic dependencies between some of the files.) (1.0 points)

  3. Background: In preparation for the first machine problem, the global variable environ provides access to the entire environment, an array of strings. The routine getenv() in the standard library gets the value of an environment variable, so getenv("PATH") gets the current search path. The search path is a single string with colons separating components, where each component is the name of a directory that should be checked whenever an application is launched.

    The C standard library includes a number of string manipulation routines, notably strncpy() for copying a null-terminated string, strstr() searches for one null-terminated string within another, and strchr() searches for the first occurance of a character in a string.

    A Problem: Write a brief chunk of code to enumerate the successive directory names in the current search path. (0.5 points)

    A Machine Problem:

    Due Monday, Feb. 14

    Take the crummy shell distributed as and make the following changes:

    Submission instructions: Your completed program should be a single file named shell.c (the .txt suffix on the web version was go guarantee that it would display as plain text). Submit your completed work using the submit shell command, giving shell.c ass the file name, and submitting your work for the course c_112 and the assignment mp1. The submit command gives verbose feedback and complete instructions. Follow them.