Lab 11: Programming in Pseudo-Assembly

The goal if this lab is to give you a feel for what assembly programming is like.

1. Introduction and setup

In class we have seen examples of programs written for our virtual machine. In this lab you will try your hand at writing a program yourself.

Copy the code for the virtual machine and disassembler from the course directory.

cp ~tvandrun/Public/cs245/lab11/* .

2. Your task

Write a program gcd.asm that computes the greatest common divisor of 180 and the integers from 18 to 24 (so, the gcd of 180 and 18; the gcd of 180 and 19; etc). In particular implement a program from the following pseudo-code:

for (i = 18; i <= 24; i++) {
    a = 180;
    b = i;
    while (b != 0) {
         temp = a mod b;
         a = b;
         b = temp;
    }
    print a;
}

Then produce the raw virtual machine code using the provided assembler. I wrote the assembler in Java; use it with

java Assembler gcd.asm

3. Hints

First decide what register you will use for each variable. Then, separate the code into sections using labels.

One of the hardest parts will be computing the mod, since our language does not have a mod operator. You'll need to figure out yourselves how to do that using the arithmetic operators you have.

4. To turn in

Turn in a hard copy of a typescript showing your pseduo-assembly code and the result of it running.


Thomas VanDrunen
Last modified: Wed Mar 30 14:58:42 CDT 2011