I am looking for some help with the fibonacci in Mips. Yes, I am a student (part time). Yes, I have made an attempt which is below. Yes, I have tried looking for help, hence me finding this forum.

I have the values for the previous value, $t3, and the value for the second to last value found, $t4. I am adding these into %t5. My question is how can I store the value in %t5 in to my array which is stored in %s0? Please excuse the inefficiency as I am a newbie to assembly.


fibarray: .word 0,1,0,0,0,0,0,0,0,0
ori $s0, $zero, fibarray
ori $t0, $zero, 2
ori $t1, $zero, 10
ori $t2, $zero, 1
daddi $s0, $s0, 16
sd $t0, 0($s0)

daddi $t3, $s0, -4
daddi $t4, $s0, -8
dadd $t5, $t4, $t3
daddi $s0, $t5, 0

daddi $s0, $s0, 8
daddi $t0, $t0, 1 # increases counter
bne $t0, $t1, loop

Could you clarify the problem. Is it supposed to be a function and does the array have some max size?

The program is supposed to calculate the first 10 numbers of the fibonacci sequence. However, the first to numbers, 0 and 1, can be assigned outside of the loop. While the rest of the numbers are to be generated inside of the loop. My main problem is how to store a result in the array, and in the correct index of the array.


All you need to do is loop through the array, have three pointers if you will, one that points at element 1, the other at 2 and the third at 3. In your loop add 1 and 2 and put them in 3. Then after that, increment every pointer by one.

thank you for the help, I was able to get the code to calc the correct results from the previous values.

By the way, love the icon. Futurama rocks!!!

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.