EECS 473 - MP6: Simple Code Generation

Due: April 30, 2001 at 11:59 pm

For this assignment, you will need to generate the static memory segment for program and the memory storage commands for items in that segment using the bison code that you created for mp5. If the program contains a semetic or syntactic error, no code is to be generated.

We will assume that the memory is word alligned (word size is 4 bytes), characters require 1 byte and integers require 4 bytes. The items are to be laid out in order that they are declared in the program. When an integer is declared in memory it must start at an address that is a multiple of 4; therefore, if the next available memory address is not a multiple of 4 when an integer is to be declared, add either 1, 2 or 3 to the address to get to the next alligned memory address. The memory skipped over will be wasted. This program is not to do any memory management scheme to make memory declaration efficient.

Once the total number of words of memory is know, print out the following lines:

	.data
	.word 0:X
	.text
where X is the number of words needed to store the static memory segment. We will treat the file scope (global) variables and the local variable of main() as both being elements in the static memory segment.

After the static memory allocation line in printed, you are to print the memory storage line for the left hand side of every assignment statement. These statements will be of the form:

	sw	$R, <offset>($28)
or
	sb	$R, <offset>($28)
The "sw" line is used if the element on the left hand side is a variable of type integer. The "sb" line is used if the element on the left hand side is a variable of type character. The <offset> value distance from the beginning of the static memory element of the left hand side element. For example, consier the following code:
int val1;
char val2;
int val3;

void main ()
{
 val1 = 0;
 val2 = 0;
 val3 = 0;
}
The output would be:
	.data
	.word 0:3
	.text
	sw	$r, 0($28)
	sb	$r, 4($28)
	sw	$r, 8($28)
This program is to be electronically submitted using the turnin command with the project name of mp6.