so here is the procedure in MIPS language
for calculating Fibonacci number(Recursion)
#####################################################################
# Display fibonacci sequence.
# The Fibonacci Sequence is defined as follows:
# fibonacci
# if n=1 or n=0
# fibonacci
= n
# if n >= 2
# fibonacci
= fibonacci(n-2) + fibonacci(n-1)
# -----
# Arguments:
# $a0 - n
# Returns:
# fibonacci
.globl fibonacci
.ent fibonacci
fibonacci:
####Save registers####
sub $sp, $sp, 8
sw $ra, ($sp)
sw $s0, 4($sp)
move $v0, $a0 #number to $v0
ble $a0, 1 , fib_done
move $s0, $a0 #copy the number to $s0
sub $a0, $a0, 1
jal fibonacci
sub $a0, $s0, 2
move $s0, $v0
jal fibonacci
add $v0, $v0 ,$s0
fib_done:
####Restore Registers####
lw $ra, ($sp)
lw $s0, 4($sp)
addu $sp, $sp, 8
jr $ra
.end fibonacci
just need to make a procedure that calculates Perrin number
my prof said you just need to add a couple of lines of code on the fibonacci sequence procedure.
here is the formula
#####################################################################
# Display perrin sequence.
# The Perrin Sequence is defined as follows:
# perrin
# if n=0
# perrin
= 3
# if n=1
# perrin
= 0
# if n=2
# perrin
= 2
# if n > 2
# perrin
= perrin(n-2) + perrin(n-3)
# -----
# Arguments:
# $a0 - n
# Returns:
# perrin
idk if there are programmers here. but fu.ck it, might as well try
for calculating Fibonacci number(Recursion)
#####################################################################
# Display fibonacci sequence.
# The Fibonacci Sequence is defined as follows:
# fibonacci
# if n=1 or n=0
# fibonacci
# if n >= 2
# fibonacci
# -----
# Arguments:
# $a0 - n
# Returns:
# fibonacci
.globl fibonacci
.ent fibonacci
fibonacci:
####Save registers####
sub $sp, $sp, 8
sw $ra, ($sp)
sw $s0, 4($sp)
move $v0, $a0 #number to $v0
ble $a0, 1 , fib_done
move $s0, $a0 #copy the number to $s0
sub $a0, $a0, 1
jal fibonacci
sub $a0, $s0, 2
move $s0, $v0
jal fibonacci
add $v0, $v0 ,$s0
fib_done:
####Restore Registers####
lw $ra, ($sp)
lw $s0, 4($sp)
addu $sp, $sp, 8
jr $ra
.end fibonacci
just need to make a procedure that calculates Perrin number
my prof said you just need to add a couple of lines of code on the fibonacci sequence procedure.
here is the formula
#####################################################################
# Display perrin sequence.
# The Perrin Sequence is defined as follows:
# perrin
# if n=0
# perrin
# if n=1
# perrin
# if n=2
# perrin
# if n > 2
# perrin
# -----
# Arguments:
# $a0 - n
# Returns:
# perrin
idk if there are programmers here. but fu.ck it, might as well try