So I am doing a fibonacci series for my MIPS assembly programming class and I am
ID: 3544920 • Letter: S
Question
So I am doing a fibonacci series for my MIPS assembly programming class and I am having a trouble with the output. I feel like my logic is correct. I have put comments in the code to allow for an easy follow through of my logic. I will explain it again on here though in non MIPS code
so we start out with a = 0 b = 12 c = 0 and d = 1 e = 0 (temporary place holder for adding)
while a is not b
e = c + d
c = d + 0
d = e + 0
add 1 to a
jump back through loop again
Maybe I am doing something wrong here, but I feel like my logic is correct.
For some reason my output is 0 which is really baffling me.
Explanation / Answer
please rate - thanks
you have branch not equal, instead of branch if equal
.data
str: .asciiz "One pair of rabbits can produce "
str2: .asciiz " pairs in a year."
.text
.globl main
main:
la $a0, str #prints out str
li $v0, 4
syscall
li $t0, 0
li $t1, 12
li $t3, 0
li $t4, 1
Loop1:
beq $t0, $t1, end1 #branch if not equal
add $t5, $t3, $t4 #add t3 and t4 put in t5
addi $t3, $t4, 0 #add t4 and 0 put in t3 (t3 becomes n-2)
addi $t4, $t5, 0 #add t5 and 0 put in t4 (t4 becomes n-1)
addi $t0, $t0, 1 #add 1 to t0
j Loop1 #jump loop
end1:
move $a0, $t5 #move t5 into a0 and print
li $v0, 1
syscall
la $a0, str2
li $v0, 4
syscall
li $v0, 10 #exit program
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.