CS31 Written Homework 1:
IA32 Practice

Due before 2pm Friday Oct. 4
Hand a print-out or a hand written solution to Bridget in the main CS office before 2pm

Written assignments are not worth as much as lab assignments, but are designed to give you some extra practice on lecture material and on some of the type of questions you may see on course exams.

You are allowed to work with one or two classmates of your choice, but no more than two, or you may work alone. However, I suggest working together to compare answers and submit a single joint solution.

If you work with a partner(s) only one of you should submit yor joint solution (and make sure all of your names are on it).

First run update31, and you will get a written_hw/01 subdirectory.

$ update31
$ cd cs31/written_hw/01
$ ls
README diss.s

Problem Details
The README file contains a summary of these instructions.

You will solve 2 problems: the first can be written up in the diss.s file and then printed out, or you can print out diss.s and write your answers on the print out. To print on our system:

  lpr diss.s
Questions:
  1. Translate IA32 to C: In the diss.s file is a sequence of IA32 assembly code.
    1. annotate each instruction with what it is doing in terms expressions involving the local variables x,y,z and the registers. Assume that these variables are on the stack at locations:
        x is at R[%ebp]-4
        y is at R[%ebp]-8
        z is at R[%ebp]-12
      
    2. list the full C code translation of this code fragment You cannot use goto in this part, but you could think about a goto version as a first step if you are having trouble getting going on this.
    For this problem you can either print out the diss.s file and write your answers in with pen, or you can add your answers in the diss.s file in vim, and then print out the result.

  2. C to IA32: Convert the following C code fragment to equivalent IA32 assembly code:
       res = 0;
        while(i < n) {
          res = res +i;
          i++;
        }
    
    You will do this in two steps, and show both steps:
    1. first, translate the loop to its equivalent C goto version
    2. next, translate your C goto version to IA32 For this part, assume that res, n and i are local variables, located on the stack at the following addresses:
          res is at R[%ebp]-4
          n   is at R[%ebp]-8
          i   is at R[%ebp]-12
      
      To receive partial credit annotate your IA32 code with comments describing what it does

    Submit

    Submit a printout/hard-copy of your answers by the due date to Bridget in the main CS office. Make sure your name(s) are clearly printed on what you hand in, and if you work with a partner(s), please only submit a single joint solution, and please staple all your pages together.