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.
-
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)
-
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; it should be much
shorter than a page.
Note to C++ programmers: Please avoid using C++ comment conventions.
(1 point)
-
Modify the program so that it outputs, in hexadecimal, the address of
your string instead of outputting the text of the string.
To output the pointer p in hex using C, assuming that pointers
are 24 bits (they aren't on any of our machines),
use printf("%6x",p) (the 6 is the number of digits per pointer).
Again, turn in a legible printed copy of this short program (it ought to
fit on the same page as the first one).
(1 point)
-
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
any of several common UNIX editors can be made to do this.
Report on your methodology, giving details of how you did it.
(1 point)
-
Write a C or C++ function that prints out the address of the first
local variable in its activation record,
in hex, with a main program that demonstrates it.
(1 point)