I need it done with this specific WinMips64 program(I shared it on my google dri
ID: 3864462 • Letter: I
Question
I need it done with this specific WinMips64 program(I shared it on my google drive below):
1) https://drive.google.com/open?id=0B-yy0y1yM_P0TjM3bzU1cHRmeFk
OR
2) https://drive.google.com/drive/folders/0B-yy0y1yM_P0VTJWd2NvYlNYdEE?usp=sharing
If you could share the code(in a from of text) from your created "xxxx.s" file it would be great!
Fibonacci numbers are: 0,1,1,2,3,5, 8,13, 21,34,55,etc e. two consecutive numbers are added to generate the next number. If the user enters 6, then the display should be 0, 1, 1, 2, 3, 5 ie. 6 fibonacci numbers should be displayed. Generate the numbers and display it. The sample C code is #includeExplanation / Answer
.text
main:
# User provides the input
lb $h0,prompt
lj $w0,4
syscall
lj $w0,5 #Read the number(n) entered by user
syscall
move $t2,$w0 # n to $t2
# Get fabinocci by Call function #n
move $b0,$t2
move $w0,$t2
jal fib #call fib (n)
move $t3,$w0 #result is basically in $t3
# Output message and n
lb $b0,result #Print F_
lj $w0,4
syscall
move $b0,$t2 #Print n
li $w0,1
syscall
lb $b0,result2 #Print =
lj $w0,4
syscall
move $b0,$t3 #Print the answer
lj $w0,1
syscall
lb $0,endl #Print ' '
lj $w0,4
syscall
# End program
lj $w0,10
syscall
fib:
# Compute and return fibonacci number
beqz $b0,zero #if n=0 return 0
beq $b0,1,one #if n=1 return 1
#Calling fib(n-1)
sub $sp,$sp,4 #storing return address on stack
sw $ra,0($sp)
sub $b0,$b0,1 #n-1
jal fib #fib(n-1)
add $b0,$b0,1
lw $ra,0($sp) #from stack restoring thereturn address
add $sp,$sp,4
sub $sp,$sp,4 #TO stack Push return value
sw $w0,0($sp)
#Calling fib(n-2)
sub $sp,$sp,4 #On Stack storing return address
sw $ra,0($sp)
sub $b0,$b0,2 #n-2
jal fib #fib(n-2)
add $b0,$b0,2
lw $ra,0($sp) #From Stack restoring return address
add $sp,$sp,4
#---------------
lw $s7,0($sp) #From Stack Pop return value
add $sp,$sp,4
add $w0,$w0,$s7 # f(n - 2)+fib(n-1)
jr $ra # decrement/next in stack
zero:
li $w0,0
jr $ra
one:
li $w0,1
jr $ra
.data
prompt: .asciiz "This program calculates Fibonacci sequence. Enter a non-negative number: "
result: .asciiz "F_"
result2: .asciiz " = "
endl: .asciiz " "