WeChat:lovexc60
CSC 311 Fall 2019
Milestone #4
Instructions
Submit your completed work using Blackboard before the deadline.
Submit the Byacc/J file and screenshots of the final output running in the simulator.
Project Description and Requirements
The goal of this milestone is to perform code generation, taking a program input and generating MIPS assembly code.
Start the milestone by first downloading the files provided for Milestone 4.
Semi-functional code is provided for you to give you a good starting point.
The requirement for this milestone is to take the any valid input program (such as the example shown on Page 2), and generate the corresponding assembly code (example shown on Page3). Below are the guidelines.
Then the HashMap should have <Key,Value> as <x, $t0>
Grading Criteria
Input Program:
PROGRAM example;
INT x = 1;
INT y = 3;
INT i = x + y;
PRINT (i)
BEGIN
STRING s = “and”;
PRINT (s)
BEGIN
FLOAT a = 1.1;
FLOAT b = 2.2;
FLOAT f = a + b;
PRINT (f)
END
END
.
Output Assembly:
.data ## Data declaration section
x: .word 1 # store value in word
y: .word 3 # store value in word
.text ## Assembly language instructions go in text segment
main: ## Start of code section
lw $t0, x # load contents of RAM location into $t8: $t8 = x
lw $t1, y # load contents of RAM location into $t9: $t9 = y
add $t2, $t1, $t0 # add
li $v0, 1 # load code into register $v0; 1 == print int
move $a0, $t2 # move integer to be printed into $a0: $a0 = $t2
syscall # call operating system to perform operation
.data ## String to be printed:
out_string: .asciiz “and”
.text
li $v0, 4 # system call code for printing string = 4
la $a0, out_string # load address of string to be printed into $a0
syscall # call operating system to perform operation
.data
fp1: .float 1.1
fp2: .float 2.2
.text
l.s $f0, fp1
l.s $f2, fp2 # the arguments to double precision instructions must be even-numbered registers.
add.s $f4, $f0, $f2 # add
li $v0, 2 # load code into register $v0; 1 == print int
mov.s $f12, $f4 # move int to be printed into $a0: $a0 = $t2
syscall # call operating system to perform operation
li $v0, 10 # terminate program
syscall # call operating system to perform operation