Am trying to do up a Fibonacci sequence for MIPS (School requires us to make use of HASE Simulator). I have done up the following code but the output seems to be a tad wrong.

ADDI R2 R0 1
ADDI R3 R0 1
ADDI R4 R0 1
ADDI R1 R0 10
ADD R5 R2 R3
ADDI R7 R4 1
ADDI R6 R4 2
ADDI R4 R4 3
SLL R8 R7 2
ADD R3 R5 R2
SLL R9 R6 2
SLL R10 R4 2
SW R5 0(R8)
ADD R2 R3 R5
SW R3 0(R9)
SW R2 0(R10)
BNE R1 R4 loop1

My ouput is as follows: 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.

I seem to be missing another 1 before the 2. Hmm, can anybody figure out why?


Oh I forgot to SW R2 0(R0) in between the 4th and 5th lines to store the value 1 in the place of 0 in the data memory. Seems to work alright now. Output is now 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.