Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Goal is to find nth Fibonacci number. Indexing needs to start at 0. The program

ID: 3633960 • Letter: G

Question

Goal is to find nth Fibonacci number. Indexing needs to start at 0. The program has to look like the example and I am having trouble programing something that will work. Also, it must ask if the user would like to find another number at the end. It must be in MIPS assembly programing, not Java. Can someone please help?!? I has to look like the output in the example provided! THANK YOU!

Example:

Which Fibonacci number do you want: 7
Output: Number is 13 and the series is 0, 1, 1, 2, 3, 5, 8, 13
Do you want another Fibonacci number? Enter 1 for YES and 0 for NO

Explanation / Answer

.data msg1:.asciiz "Give a number: " .text .globl main main: li $v0,4 la $a0,msg1 syscall #print msg li $v0,5 syscall #read an int add $a0,$v0,$zero #move to $a0 jal fib #call fib add $a0,$v0,$zero li $v0,1 syscall li $v0,10 syscall fib: #a0=y #if (y==0) return 0; #if (y==1) return 1; #return( fib(y-1)+fib(y-2) ); addi $sp,$sp,-12 #save in stack sw $ra,0($sp) sw $s0,4($sp) sw $s1,8($sp) add $s0,$a0,$zero addi $t1,$zero,1 beq $s0,$zero,return0 beq $s0,$t1,return1 addi $a0,$s0,-1 jal fib add $s1,$zero,$v0 #s1=fib(y-1) addi $a0,$s0,-2 jal fib #v0=fib(n-2) add $v0,$v0,$s1 #v0=fib(n-2)+$s1 exitfib: lw $ra,0($sp) #read registers from stack lw $s0,4($sp) lw $s1,8($sp) addi $sp,$sp,12 #bring back stack pointer jr $ra return1: li $v0,1 j exitfib return0 : li $v0,0 j exitfib

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote