首页 » Mips辅导 » Mips汇编辅导 | CSC 311 Fall 2019

Mips汇编辅导 | CSC 311 Fall 2019

这个Milestone是实现执行代码生成,接受程序输入并生成MIPS汇编代码

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.

 

  1. Maintain a HashMap of “Variable Name” and “Register Name”. Whenever you are assigning a value to a variable name, you should save this information into the HashMap.
    1. For example: INT x = 1; This line can be translated to “x: .word 1    lw $t0, x”.

Then the HashMap should have <Key,Value> as <x, $t0>

 

  1. The skeleton code only has intRegisters[]. You will need to have a floatRegisters[] and use that to do floating point assembly code.

 

  1. Ordering of the assembly is important. Also data should be grouped inside .data section and code should be grouped in .text section. You can have multiple .data and .text section but ONLY one .main label to indicate where your program starts.
    1. To keep data and text in separate blocks, you could consider adding the generated assembly into 2 lists: one for data and one for text block. And at the end, simply loop through the lists to print the final assembly.

 

  1. Your compiler should output the assembly and be able to run the assembly through MARS simulator.
    1. Do not worry about freeing registers or re-using registers.

Grading Criteria

  1. Uses HashMap to maintain variable names to register names – 10%
  2. Output assembly code for INT operations – 20%
  3. Uses floatRegisters array and can generate assembly for FLOAT operations – 20%
  4. Output assembly code for STRING operations – 20%
  5. The final assembly code is valid and able to run in simulator without any errors – 20%
  6. Screenshot of assembly running in simulator with output – 10%

 

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


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论

您的电子邮箱地址不会被公开。