[SOLVED] NCTU_CO - Computer Organization -HW1- MIPS Programming

30.00 $

Category:

Description

5/5 - (1 vote)

Goal:

In hw1,  will learn how to write MIPS code, and know the difference between assembly and high-level languages. In order to test the correctness of program, students should use a MIPS simulator –MARS to simulate the programs.

 

2.Download and Using MARS:

  1. Download and installation:

1.Download MARS from the page:  http://courses.missouristate.edu/KenVollmar/MARS/

2.Download the version chosen by yourself, and install it

 

  1. Steps for running a MIPS code on MARS:

1.File ->New

2.Write MIPS code

3.Run -> Assemble (F3)

4.Run -> Go (F5)

 

A. Factorial

The attached files factorial.c and factorial.s are modified from the example given in textbook for computing n!. In this part, please execute factorial.s on MIPS simulator MARSfor practice.

 

B. Prime number (30%)

Read an number from standard input, and judge if it’s a prime number or not. If it is a prime number, then print ”It’s a

prime” on standard output. Otherwise, print “It’s not a prime”.

(Hint: DIV instruction calculates both quotient and remainder )

 

C. Draw a diamond (30%)

Input a number n, draw a diamond with the length of its diagonal line equal to 2n-1. The following picture is an example.

 

 

 

D. Fibonacci sequence (40%)

Read a number from standard input. Output the n-th item of Fibonacci sequence. Students are required to use recursive function to solve this task.

 

 

 

  1. Notes
  2. For every task, the corresponding implement in C is provided.

 

  1. There’s no strict regulation of input and output format string, but try to be as clear as you can. You can follow the format in reference .c files.

 

.

 

  1. Here’s the document of MIPS instruction set. https://s3-eu-west-1.amazonaws.com/downloadsmips/documents/MD00565-2B-MIPS32-QRC-01.01.pdf