Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using SPIM, please write and test a MIPS assembly program that computes a Fibona

ID: 652745 • Letter: U

Question

Using SPIM, please write and test a MIPS assembly program that computes a Fibonacci sequence. A Fibonacci number sequence is formed by starting with any two numbers, adding those to get a third number, adding the second and third to produce a fourth number and so on. The first two numbers should be provided by user through keyboard. The first 10 numbers in the Fibonacci sequence (starting with the given two numbers) should be printed on screen.

Example Input: 3 8

Output: 3 8 11 19 30 49 79 128 207 335

Explanation / Answer

Program done well and added comments to...comments start with tag '#'

.data
msg1:.asciiz "Give a first number : " #message to ask user
msg2:.asciiz "Give a second number: " #message to ask user
.text
.globl main
main:

li $v0,4
la $a0,msg1 #loading message
syscall #print msg
li $v0,5
syscall #read an int
add $a0,$v0,$zero #move to $a0

li $v0,4
la $a1,msg2 #loading message
syscall #print msg
li $v0,5
syscall #read an int
add $a1,$v0,$zero #move to $a1

jal fibonacci #call fibonacci method

fibonacci:

li $v0 ,10 # initializing counter max to 10 so that 10 numbers has to be print
syscall
move $t0,$v0
li $t1,0 #counter initialized to 0
loop:
addi $t1,$t1,1 # counter incrementing by 1 every time loop executes

add1 $a2, $a0, $a1 # adding two numbers given and storing in $a2
li $v0,1
la $a0,$a2 # preparing to print calculated value
syscall #print msg
li $a0,$a1 #storing back and initializing numbers to calculate next sum
syscall
li $a1,$a2 #initializing numbers to calculate next sum
syscall
#checking whether counter=10?
beq $t0,$t1,done # here checking goes
j loop # loop ending
done:

output

Give a first number :3

Give a second number : 8

3 8 11 19 30 49 79 128 207 335

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote