This project will give you practice in writing in an assembly-like language.
In class we have seen some examples of programs written for our virtual machine. In this project you will try your hand at writing a program yourself.
Copy the code for the virtual machine and disassembler (and related tools and examples) from the course directory.
cp -r /homes/tvandrun/Public/cs245/proj8/* .
Write a program gcd.asm
that computes the
greatest common divisor of 180 and the integers from
18 to 24, using the Euclidean algorithm.
In particular, implement a program from the following pseudo-code:
for (i = 18; i <= 24; i++) print gcd(180, i); int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a mod b); }
The virtual machine, however, doesn't use asm
files.
It needs a vml
file---that is, your assembly program
must be assembled into a program in the machine language.
I have provided an assembler tool, the program assembler.py
.
It's written in Python, so you're not expected to know how it works
(although if you're curious about Python, you're welcome to look at it).
You can use it this way:
./assembler.py gcd.asm
It will produce a file gcd.vml
which you can then
run using the provided virtualmachine.c
.
(I have also provided disassembler.c
in case
you find it useful to reverse the process that assembler.py
does.)
Please turn in your gcd.asm
to the turn-in directory:
cp gcd.asm /cslab.all/ubuntu/cs245/turnin/(your user id)/proj8
DUE: Monday, May 5, 5:00 pm. You may not use late days for this assignment but you will receive extra credit pointes for ever day prior to the duedate that you hand it in early..