CSCI 210: Lab 3

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

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 pgoram 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 (using syscall 1).
  • the number in hexadecimal.
  • the number of 1-bits in the binary representation of the number.

For the example above, you would display

  
	3	0x00000003   2
	1	0x00000001   1
	4	0x00000004   1
	5	0x00000005   2
	9	0x00000009   2
	14	0x0000000E   3
	23	0x00000017   4
	37	0x00000025   3
	60	0x0000003C   4
	97	0x00000061   3
  
  

The hex version can be displayed using system call 34.

Implementation

You will not need to use either arrays or recursion for this problem. You are required to write a function which counts the number of ones in a number. (Hint: Think about using bit operations to isolate each bit in the number, and add them together.)

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.

Helpful Resources

Submission

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


C. Taylor