Assignment 1, due Jan 29

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

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday), and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.

  1. Find a C compiler, any C or C++ compiler on any computer system. Veryfy that you can actually compile programs under it and that it produces an executable object file that you can find in some file system. Name that compiler and identify the computer system on which it works. (1 point)

  2. Compile and run the C Hello World program from lecture 2. Change the program so that it contains a comment giving your name and so that it outputs your name instead of the string Hello World (see the C style guidelines cited in lecture 2 for a suggested commenting convention). Turn in a legible printed copy of this modified program. Note to C++ programmers: Please avoid using C++ comment conventions. (1 point)

  3. Modify the program so that it outputs, in hexadecimal, the successive bytes of your string instead of outputting them as characters. To output the character ch in hex using C, use printf("%2x",ch). Add a blank between successive characters for legibility. Again, turn in a legible printed copy. (1 point)

  4. Figure out how to modify the a.out object file! For example, replace all instances of your name in the object file with a nonsense string of the same length. The worst case solution to this problem would involve writing a little program that reads, modifies and writes the object file, but the UNIX sed utility can be made to do this for you. Report on your methodology, giving details of how you did it. (1 point)

  5. Write a C or C++ function that prints out the return address of its caller, in hex. You'll have to write the function so it prints out a range of addresses, then call it several times to see what address is the return address, then narrow the range so it prints only the return address. Print out and turn in your finished function. Make sure you document what version of C or C++ it is tuned to work with. Note that there are 32 and 64-bit compilers on the departmental machines, so return addresses may be either size, depending on the compiler you use. (1 point)