Ancient CS 61 Content Warning!!!!!1!!!
This is not the current version of the class.
This site was automatically translated from a wiki. The translation may have introduced mistakes (and the content might have been wrong to begin with).

Learning Objectives

Getting Started

Pull an updated copy of the cs61-exercises repository. We are working in the l07 directory.

Run make to build all the .s files.

Today we're going to ask you to examine the .s files and reverse engineer the C programs. Please do not cheat! You will learn a lot more by trying to write the C programs and then comparing them to the actual ones!

Reverse Engineering C

1. Begin with the file 20.s. Write C code that performs the same function as the one in 20.s. After you and your partner agree that you have the right code, compare it with the code in 20.c and determine if your code and our code are equivalent (they need not be identical; they should just be semantically equivalent). For example:

if (a > b) return 0; else return 1;

is the same as:

if (a <= b) return 1; else return 0;

You might interpret a single piece of assembly code for either of these.

2. Now look at 21.s. You will find that there is some code at the beginning the enforces the x86 calling conventions - don't stress too much about those -- they are covered in the calling conventions video. You aren't responsible for that until next class, although we strongly encourage you to view it before the weekend so that you're better prepared to tackle Assignment 2 over the weekend.

This function is a bit trickier than others you've worked with. Take your time and do your best at reverse engineering the C code before looking at the 21.c file.

3. OK, now tackle files 22-26.s. These all embody some standard control flow structures in C. Do your best to reverse engineer the C before looking at the source code!

Before you Leave

Please complete the post class survey.