Programming Assignment 1 (20 pts)

Deadline: April 14, 2020 by 12:30:00 PM

The goal of this assignment is to become familiar with the setup that will be used for future
assignments, such as the use of a virtual machine, as well as the
basics of working with gdb and writing programs in x86 assembly.

Getting Started

To complete this assignment, you will be provided with a VirtualBox VM pre-populated with the
assignment files.

VM Image

In order to match the environment in which your submission will be graded, all work for this
assignment must be done on the VirtualBox VM we provide, named pa1box. You can download the VM
image here.

The VM is configured with two users: student, with password hacktheplanet; and root, with
password hackallthethings. The VM is configured with SSH on port 2222. Please note that SSH is
disabled for root, so you can only SSH in as the student user. You can still log in as root
using su or by logging into the VM directly.

To SSH into the VM:

ssh -p 2222 student@127.0.0.1

To copy files from your computer to the VM:

scp -P 2222 -r /path/to/files/ student@127.0.0.1:/home/student

To copy files from the VM to your computer:

scp -P 2222 student@127.0.0.1:/path/to/files/ /destination/path

Part 1: Using GDB (10 pts)

Files for this sub-assignment are located in the gdb subdirectory of the student user's home
directory in the VM image; that is, /home/student/gdb. SSH into the VM and cd into that
directory to begin working on it.

Inside the gdb directory, you'll find fib.c, a C program demonstrating the Fibonacci sequence;
a Makefile; and hw1.txt, in which you'll record your responses to the questions below. The
first step is to compile fib by running make on the command line.

To run the fib executable in GDB, run gdb fib.
I recommend the following workflow in GDB:

  1. Starting. Set breakpoints that you can later use for analysis:

  2. Analyzing. Examine memory, registers, etc; disassemble code; show stack frames, backtrace,
    etc; and more:

  3. Continuing. Continue analysis:

Note that this is only a cursory overview of GDB; much more info is available from online
resources.

Assignment Instructions

Play with gdb fib to complete the following exercises.

  1. What is the value, in hex, of the ecx register when the function f is called? (4 pts)
  2. Which register stores the value of the variable i in the main function before entering the for loop body? (4 pts)
  3. What is the address, in hex, of the function f? (4 pts)
  4. What is the name of the 6th instruction of the function f? (4 pts)
  5. When f completes after being called from main, to which address in main does control
    return? Write your answer in hex form. (4 pts)

Submission

Fill your answers to the above questions on Gradescope assignment PA1. Strictly follow the format of sample answers given there.