Function Call Homework

Due anytime on Thurs, April 19

This is an individual homework. Each student is to submit this homework on his/her hw330-1 mapped network drive.

Write a Mac-1 machine language program (in both assembler notation and in binary) that in essence is the compiled code for the following C++ program. Make sure that it runs correctly on the simulator. Make no optimizations. Assume that whatever compiler generated the Mac-1 code blindly followed our outlines of how each feature is handled. (Thus, for example, the local variable c, which is clearly redundant, is not eliminated. Similarly, the a = c assignment would begin by looking up the value of variable c in main memory, even though the AC probably already contains this same value.) A more useful program would print the result of its computation, but since the simulator cannot do I/O, we won't worry about that.

void compute(int b, int & a)
   {
   int c;
   c = b + 5;
   a = c;
   }

void main(void)
   {
   int x, y;
   x = 14;
   y = 8;
   compute(y, x);   // Get the order right!  The compiler would put y on the stack first.
   }

Begin by copying mic004.txt to a new file called mic036.txt and edit it as needed. Do not change any of the microcode, as it is the microcode that interprets the Mac-1 instructions and is correct as is.

Assume that main's two variables are kept at the bottom of the stack. That is, x is at location 68 and y at location 67. Thus you would begin your Mac-1 program as follows:

0: DESP 2      ; save space for x and y
1: LOCO 14
2: STOD 68     ; give x its initial value
3: LOCO 8
4: STOD 67     ; give y its initial value

Hint: Although you do not have to turn it in, you should carefully draw for yourself a picture of the run-time stack.

Name your program file mic036.txt. Follow my format for such a file. This includes placing your name and a brief description of the program at the top of the file as comments. (Be sure that none of the comment lines start with a digit, as they would then not be seen as comment lines by the simulator.) Put the assembler version of your Mac-1 code at the bottom of the file.