Lab 3 -- Conditionals and Loops

Introduction

In this lab you will be exploring the C to assembly mapping. You may work in groups but each member should submit his/her own writeup. Please note all collaborators on your writeup.

The assignment consists of the following steps:

  1. Place the three following code snippet is three separate functions.
  2. Compile the C-code to assembly: gcc program.c -O0 -S (e.g., use optimization level zero and produce the .s assembly file)
  3. Produce a side-by-side comparison of the produced assembly to the C-code. For this lab, we'll restrict our focus to the 32-bit assembly (i.e., the Jazz machines).

Code Snippet 1

int x = 32; if(x < 24) { x++; } else { x--; } return x;

Code Snippet 2

int x = 0; int z = 0; while (x < 32) { z += 34; x++; } return z;

Code Snippet 3

int x; int z = 0; for (x = 0; x < 32; x++) { z += 34; } return z;

Complete the Lab by submitting your report to Moodle in .pdf format.