CS4121 Cminus Compiler Project 3: Implementing Arrays, Conditionals and Iteration


5/5 - (3 votes)

CS4121 Cminus Compiler Project 3: Implementing Arrays, Conditionals and Iteration

The purpose of this project is to gain experience in giving meaning to a programming language by generating
x86-64 for a subset of Cminus. Specifically, you will be generating assembly for if-statements, while-loops
and integer arrays.
Project Summary
In this project, you will add actions to the compiler developed in the previous project that will do the
1. Generate assembly to test the results of an expression controlling an if-statement or while-loop.
2. Generate assembly to branch through an if-then-else statement as determined by the controlling expression
3. Generate assembly to branch back to the beginning of and out of a while-loop as determined by the
controlling expression.
4. Reserve space for an array of integers.
5. Generate address arithmetic for an array reference.
Follow the methods given in class for generating code for if-statements, while-loops and arrays. Note that
an array is laid in memory from low address to high address, and variables, including both scalar and array
variables, must be contiguous.
Write all of your code in C or C++ . It will be tested on the Rekhi CS lab machines and MUST work
there. You will receive no special consideration for programs which “work” elsewhere, but not work on the
lab machines.
Input. I have provided my solution to Project 2 as a Makefile project in CminusProject3.tgz. Sample
input is provided in the directory CminusProject3/input. I will go over my code for those who wish to use
it. To run your compiler, use the command
cmc <file>.cm
which will output to <file>.s.
To create an executable, run the following command on the assembly file
gcc -o <file> <file>.s
You may then directly run the executable.
Submission. Your code should be well-documented. You will submit all of your files, by tarring up the
working directory using the command
tar -czf CminusProject3.tgz CminusProject3
Submit the file CminusProject3.tgz via Canvas. Make sure you do ’make clean’ of your working directory
before executing the tar command. This will remove all of the ’.o’ files and make your tar file much smaller.

PlaceholderCS4121 Cminus Compiler Project 3: Implementing Arrays, Conditionals and Iteration
Open chat
Need help?
Can we help?