Computer Organization and Structure

Homework #2

Due: 2010/10/26

Please write the following three programs in MIPS assembly language.

1.      Simple Calculator (30%):

We will give you two integers x, y (0 < x, y < 100), and your job is to write a simple calculator with the four operators (+, -, *, /). You donft have to consider about the remainder from the division operator (/). The filename is Calculator.s.

Your output should look like this.

----Simple Calculator----

7

+

3

10

2.      Bubble Sort (35%):

Your job is to implement a bubble sort algorithm in MIPS.

Bubble sort includes repeated steps through the list to be sorted. Each step is comparing each pair of adjacent items and swapping them if they are in the wrong order. The algorithm ends until no swaps are needed, namely, the sorting is done. The inputs are 5 integers, and the output is the sorting result. Here is a sample code. You can fill the missing functions in the sample code or implement by yourself. By the way, any change in the sample code is allowed. The filename is BubbleSort.s.

Your output should look like this.

----Bubble Sort----

Please insert an integer: 1

Please insert an integer: 3

Please insert an integer: 5

Please insert an integer: 7

Please insert an integer: 2

Vector contents: 1 2 3 5 7

3.      Tower of Hanoi (35%):

Your task is to complete a recursive implementation of the Tower of Hanoi problem in order to get familiar with assembly programming. The input is integer n (0<n<10) which means Tower of Hanoi with n disks. You will need to print out the moving process. Here is a sample code. You can fill the missing functions in the sample code or implement by yourself. By the way, any change in the sample code is allowed. The submitted filename is Hanoi.s.

Your output should look like this.

----Tower of Hanoi----

Please input the level:3