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

Please do it step by step and also please post the output as well. Thank you!! P

ID: 3701805 • Letter: P

Question

Please do it step by step and also please post the output as well. Thank you!!

Problem #3: ( ) Write a program to print out a series of numbers. First input a number N for the size of the list. This should not be more than 20. Next, you need to calculate F(i) for each number 0..N. This means you should print out F(0), F(1), …, F(N-1) for a total of N numbers including the zeroth number. Your series is defined as follows:

F(0) = 2

F(1) = 5

F(i) = F(i-1) + F(i-2) + 1

Like problem #2, the program should exit if the value entered for N is 0, otherwise the program should run again.

So the following would be a sample program output:

Please enter a value for N: 7

2 5 7 12 19 31 50

Please enter a value for N: 6

2 5 7 12 19 31

Please enter a value for N: 0

Done!

NOTE: Please do NOT use QtSPIM or MARS style syscall conventions. You must use the syscall convention presented in class. For instance to print a string: la $a0,stringaddr syscall $print_string

Explanation / Answer

.data
msg1:.asciiz " Enter N : "
msg2:.asciiz "Done!"
msg3:.asciiz " "
.text
.globl main
main:

# Get The Number N
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall

# If N==0 , done! else go to fib
add $a0,$zero,$v0
beqz $a0,endfunc
j fib

fib:

# checking if n==1 or n==2
addi $t0,$zero,1
add $a1,$zero,$a0
addi $a1,-1
beqz $a1,return0
beq $a1,$t0,return1

#printing first two values
addi $a0,$zero,2
li $v0,1
syscall
li $v0,4
la $a0,msg3
syscall

addi $a0,$zero,5
li $v0,1
syscall
li $v0,4
la $a0,msg3
syscall

# x(t1) , y(t2) , z(t3) , counter(t4)
# initialization x=0 , y=2 , z=5
add $t1,$zero,$zero
add $t2,$zero,2
addi $t3,$zero,5
addi $t4,$zero,1

#looping till n-1 , x = y+z , y = z , z = x
loop:
bge $t4,$a1,endloop
add $t1,$t2,$t3

#Printing the current x value
add $a0,$t1,$zero
li $v0,1
syscall
li $v0,4
la $a0,msg3
syscall

add $t2,$zero,$t3
add $t3,$zero,$t1
addi $t4,$t4,1
j loop

endloop:
# again execute main
add $v0,$zero,$t1
j main

return0:
# again execute main
addi $a0,$zero,2
li $v0,1
syscall
li $v0,4
la $a0,msg3
syscall
j main

return1:
# again execute main
addi $a0,$zero,5
li $v0,1
syscall
li $v0,4
la $a0,msg3
syscall
j main

endfunc:
li $v0,4
la $a0,msg2
syscall
li $v0,10
syscall