CS439: Principles of Computer Systems
Due: 7:45a Thursday, September 5, 2013 Homeworks
must be submitted electronically. Please refer to the
homework turnin instructions.
Which of the following components is responsible for loading the
initial value in the program counter for an application program
before it starts running?
- Boot module or boot ROM
Write a C program that expects an integer command line argument, x,
and then uses recursion to print, Hello, World! x times.
Paste the code into your homework.
Compile your program from 1) on the CS Linux machines
using gcc. Use command line options to:
- Name the executable file hello.
- Set the optimization to level 0.
Turn on the debugging information.
You may find the overview of gcc on the course homepage helpful.
What command did you use?
- Run your program from within gdb with an argument of 5.
- Set a break point at the entrance to your recursive function.
- Print the value of the argument to the function.
- Step through each line of the function until Hello,
World! is printed.
- Continue the execution until the next breakpoint is reached.
Check the value of the argument, and, if it is not the last recursive
call, continue the program.
- On the last recursive call, print a backtrace of the call stack.
Identify the line number of the call to your recursive function
What commands did you use in gdb? What is the line number of your
Return to your program and add an if statement in main after
the recursive call that reads:
if(x == x)
where x is the name of your argument to the recursive call.
Recompile your program with the optimizations set to level 4.
Run your program using gdb, but set a breakpoint
in main for after the recursive call but before the print
statement. What happens?