CSCI 210: Lab 3

MIPS Fibs
Due: 10:00 PM on Monday, October 9th

Write a program which computes a sequence of fibonacci numbers and displays it.

Preliminaries

You will write this program using the MARS MIPS simulator, which you can download here.

Click on the assignment link.

Program Specification

No starter code is provided. Create a file in MARS called lab3.asm and create your program there. You may wish to look at your code for Lab 1 for reference.

Input

Read three input values from the keyboard:

  • the first number in the sequence,
  • the second number in the sequence, and
  • the number of elements of the sequence.

Each element of the sequence (beyond the first two) is equal to the sum of the previous two. For example, if the user inputs 3, 1, and 10, then your program should generate the sequence 3, 1, 4, 5, 9, 14, 23, 37, 60, 97.

Output:

For each element of the sequence that you generate, display the following:

  • the number in decimal notation
  • the number in binary
  • the number of 1-bits in the binary representation of the number

For the example above, you would display

  
Please enter the first number: 3
Please enter the second number: 1
Please enter the length: 10
3	00000000000000000000000000000011	2
1	00000000000000000000000000000001	1
4	00000000000000000000000000000100	1
5	00000000000000000000000000000101	2
9	00000000000000000000000000001001	2
14	00000000000000000000000000001110	3
23	00000000000000000000000000010111	4
37	00000000000000000000000000100101	3
60	00000000000000000000000000111100	4
97	00000000000000000000000001100001	3
  
  

Implementation

To get full credit for this assignment, you will need to create a function to count the number of ones in a number. You should use proper function calling conventions as discussed in class. You will also need to use a loop to generate the fibanacci numbers.

You will not need to use either arrays or recursion for this problem.

Make sure to document your programs thoroughly. (This is especially important in assembly language programs, since the code itself is less easily read than high-level language code.) This should include:

  • A block of comment lines at the beginning of the source file, giving the name and author of the program and a black-box description of what it does.
  • A few comment lines between major sections of the program, describing the contents of each section.
  • A comment at the end of most source lines, describing what the instruction on that line does.

Hints

  • Write a program that does this in a high level language, then translate it to MIPS. It will be a lot easier to solve this problem if you figure out the logic first, then the translation to assembly.
  • Syscall 35 will print an integer in binary.
  • To count the ones in a number, think about using bit operations to isolate each bit of the number, and then adding the bits together. A loop will be helpful here.
  • Printing the string '\t' (the tab character) between each number will give you the nice even spacing shown in the example. Likewise, printing the string '\n' will give you a new line.

Helpful Resources

Submission

Submit the lab by committing your code and pushing it to your github repository.


C. Taylor, S. Checkoway