Question: can someone tell me if this mips assembly program is recursive or not, the function is a_n = a_(n-1) + b(n-1) and b_n = a_(n-1)

can someone tell me if this mips assembly program is recursive or not, the function is a_n = a_(n-1) + b(n-1) and b_n = a_(n-1) + b_(n-1) with a_0 = b_0 = 0 and a_1 = 2, and b_1 = 1 a_1 is in register $s1 and b_1 is in register $s2

.data

newline: .asciiz " "

prompt: .asciiz "Enter a positive integer: "

.text # Put program here

.globl main # globally define 'main'

main:

# prompt for input

li $v0, 4

la $a0, prompt

syscall

# read in the value

li $v0, 5

syscall

move $a0, $v0

li $s1, 2

li $s2, 1

fib:

bgt $a0, 1, recurse

move $v0, $s1

move $v1, $s2

jr $ra

recurse:

addi $sp, $sp, -20

sw $ra, 0($sp)

sw $s1, 4($sp)

sw $s2, 8($sp)

add $s1, $s1, $s2

lw $t2, 4($sp)

sub $s2, $t2, $s2

addi $a0, $a0, -1

jal fib

sw $v0, 12($sp)

sw $v1, 16($sp)

jal fib

lw $t0, 4($sp)

lw $t1, 8($sp)

lw $s1, 4($sp)

lw $s2, 8($sp)

jal print_result

lw $ra, 0($sp)

add $sp, $sp, 20

jr $ra

print_result:

# print result

li $v0, 1

move $a0, $s1

syscall

li $v0, 4

la $a0, newline

syscall

li $v0, 1

move $a0, $s2

syscall

li $v0, 4

la $a0, newline

syscall

jr $ra

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!