**CODE IN MIPSym ONLY** Write a program to print out a series of numbers. First
ID: 3817367 • Letter: #
Question
**CODE IN MIPSym ONLY**
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) = 4
F(i) = F(i-1) + F(i-2) -2
Like problem #2, the program should exit if the value entered for N is 0 or less, otherwise the program
should run again.
So the following would be a sample program output:
Please enter a value for N: 7
2 4 4 6 8 12 18
Please enter a value for N: 6
2 4 4 6 8 12
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
main: addi $sp, $sp, -4
sw $ra, 0($sp)
addi $a0, $zero, 5
jal fibo;
lw $ra, 0($sp)
addi $sp, $sp, 4
fibo: addi $sp, $sp, -2
sw $s0, 0($sp)
sw $s1, 4($sp)
sw $ra, 8($sp)
slti $t0, $a0, 2
beq $t0, $zero, ELSE
addi $v0, $zero, 1
jr $ra
ELSE: addi $s0, $a0, 0
addi $a0, $a0, -1
jal fibo;
addi $s1, $v0, 0
addi $a0, $s0, -2
jal fibo
add $s1, $s1, $v0
j EXIT
EXIT: lw $s0, 0($sp)
lw $s1, 4($sp)
lw $ra, 8($sp)
addi $sp, $sp, 12
jr $ra
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.