Help, Programming HW, MIPS

kentb
10+ year member

Senior VIP Member
so here is the procedure in MIPS language

for calculating Fibonacci number(Recursion)

#####################################################################

# Display fibonacci sequence.

# The Fibonacci Sequence is defined as follows:

# fibonacci(n)

# if n=1 or n=0

# fibonacci(n) = n

# if n >= 2

# fibonacci(n) = fibonacci(n-2) + fibonacci(n-1)

# -----

# Arguments:

# $a0 - n

# Returns:

# fibonacci(n)

.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(n)

# if n=0

# perrin(n) = 3

# if n=1

# perrin(n) = 0

# if n=2

# perrin(n) = 2

# if n > 2

# perrin(n) = perrin(n-2) + perrin(n-3)

# -----

# Arguments:

# $a0 - n

# Returns:

# perrin(n)

idk if there are programmers here. but fu.ck it, might as well try

 
so here is the procedure in MIPS languagefor calculating Fibonacci number(Recursion)

#####################################################################

# Display fibonacci sequence.

# The Fibonacci Sequence is defined as follows:

# fibonacci(n)

# if n=1 or n=0

# fibonacci(n) = n

# if n >= 2

# fibonacci(n) = fibonacci(n-2) + fibonacci(n-1)

# -----

# Arguments:

# $a0 - n

# Returns:

# fibonacci(n)

.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(n)

# if n=0

# perrin(n) = 3

# if n=1

# perrin(n) = 0

# if n=2

# perrin(n) = 2

# if n > 2

# perrin(n) = perrin(n-2) + perrin(n-3)

# -----

# Arguments:

# $a0 - n

# Returns:

# perrin(n)

idk if there are programmers here. but fu.ck it, might as well try
Man, I can't remember much of the assembly language stuff. It shouldn't be hard, you're doing the same logical process with a different algorithm. You have an integer as input and depending on the value of the integer, you want to perform one of 4 operations on the integer and return your output similar to what your fibonacci routine does. Unfortunately assembly doesn't read well and its been 6 years since I've done this so you'd have to clear up a couple things before I can fully realize what the program is doing. I can read C and Java any day but not assembly.

ble $a0, 1 , fib_done

Is this doing a less-than-or-equal-to-1 comparison to $a0, and jumping to fib_done if true?

jal fibonacci

What does this line do?

For the Perrin sequence are you wanting to modify the fibonacci number and return that as output, are you calculating the Perrin number on the same input integer and having that output in addition tot he fibonacci number, or what?

 
Activity
No one is currently typing a reply...

About this thread

kentb

10+ year member
Senior VIP Member
Thread starter
kentb
Joined
Location
Las Vegas
Start date
Participants
Who Replied
Replies
3
Views
180
Last reply date
Last reply from
low00ranger
IMG_20260516_193114554_HDR.jpg

sherbanater

    May 16, 2026
  • 0
  • 0
IMG_20260516_192955471_HDR.jpg

sherbanater

    May 16, 2026
  • 0
  • 0

New threads

Top