Deadline: January 13, 2021 by 11:59:59 PM
Early Turn-In: January 10, 2021 by 11:59:59 PM (10% bonus)
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 and the included turn-in script, as well as the basics of working with gdb and writing programs in x86 assembly.
To complete this assignment, you will be provided with a VirtualBox VM pre-populated with the assignment files.
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
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:
b foo — break at function foob *0x08048489 — break at the instruction at address 0x08048489r — run the executabledisas foo — disassemble function fooi r — view registerswhere — view stack framesx <loc> — examine memoryx $eip — examine current instruction pointerx /10x $esp — examine 10 words at top of stackx /10x buf — examine 10 words in bufx /10i $eip — examine 10 instructions starting at instruction pointerx /10i foo — examine 10 instructions starting at fooc — continue execution until next breakpoint/watchpointsi — step to the next instructions — step to the next line of source codeNote that this is only a cursory overview of GDB; much more info is available from online resources.
Complete the following exercises and fill out hw1.txt with your answers.
Follow the directions in the template, do not delete the square brackets
ecx register when the function f is called? (2 pts)i in the function main? (2 pts)f? (2 pts)f? (2 pts)f completes after being called from main, to which address in main does control
return? Write your answer in hex form. (2 pts)Submit hw1.txt to "1a. gdb" on Gradescope.
Gradescope will check that it has successfully detected your answers, but it will not give you your grade
until the due date.
echo in x86 (10 pts)Files for this sub-assignment are located in the x86 subdirectory of the student user's home
directory in the VM image; that is, /home/student/x86. SSH into the VM and cd into that
directory to begin working on it.
For this part, you will be implementing a simplified version of the familiar echo command, using
raw x86 assembly code. The goal of this assignment is to familiarize you with writing programs
directly in x86.
Your echo command must behave as follows:
./echo Hello):\n)../echo) or too many (e.g., ./echo Hello
World):This command expects exactly one argument. —
followed by a trailing newline (\n) — to the console's standard error (stderr).Your code should be written in the file echo.s inside the x86 directory. A heavily-commented
example echo.s is provided, which simply prints the message Hello World (followed by a trailing
newline) to stdout. Your job is to modify this program to meet the specification for echo above.
A Makefile is included, so you can build the echo binary by running make from the command line.
argc at the top of the stack, accessible at 0(%esp) from
x86-assembly programs. Below it is argv, the array of pointers to (null-terminated) strings
passed into the program as arguments. So argv[0] can be accessed from x86-assembly programs at
4(%esp), argv[1] at 8(%esp), argv[2] at 12(%esp), and so on.argv[0] is the name of the program executed, not the first argument, which is argv[1] if
supplied (or 8(%esp) for our purposes). Then argc (or 0(%esp)) will be 1 if the program was
not passed any arguments, 2 if it was passed 1 argument, and so on.Submit echo.s to "1b. x86 echo" on Gradescope.