Question: 2 . c ) Implement a version of your program that allows: ( i ) the user to enter a value for the variable n
c Implement a version of your program that allows: i the user to enter a value for
the variable n ; and ii prints the value of fib in the terminal.
c only please, this is the code I already have. Please build upon this:
main:
li $a # Initialize n to
jal fib # Call fibn
move $a $v # Move result to $a for printing
# Exit program
li $v
syscall
fib:
addi $sp $sp # Allocate stack space
sw $ra$sp # Save return address
sw $a$sp # Save argument n
li $v # Default return value
beq $a $zero, end # if n return
li $v # Default return value
li $t
beq $a $t end # if n return
# Calculate fibn
addi $a $a
jal fib
move $t $v # Save fibn in $t
# Calculate fibn
lw $a$sp
addi $a $a
jal fib
add $v $v $t # fibn fibn fibn
end:
lw $a$sp # Restore argument n
lw $ra$sp # Restore return address
addi $sp $sp # Deallocate stack space
jr $ra # Return
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
