The goal if this lab is to give you a feel for what assembly programming is like.
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/* .
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
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.
Turn in a hard copy of a typescript showing your pseduo-assembly code and the result of it running.