*MUST BE IN MIPS LANGUAGE* Write an assembly program to print out a series of nu
ID: 3662223 • Letter: #
Question
*MUST BE IN MIPS LANGUAGE*
Write an assembly 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) = 1
F(1) = 3
F(i) = F(i-1) + F(i-2) + 1
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 1 3 5 9 15 25 41
Please enter a value for N: 6 1 3 5 9 15 25
Please enter a value for N: 0 Done!
NOTE: You must use the syscall convention. For instance to print a string: la $a0,stringaddr syscall $print_string
Explanation / Answer
.data
N: .word 1
array: .word 20
.text
main:
back:li $v0, 5
syscall
bgt $v0,20,back
beq $v0,0,exit_program
sw $v0, N
move $t4,$v0
#load the initial values and start
li $t0,1
li $t1,3
la $t2,array
sw $t0, ($t2)
addi $t4,$t4,-1
beq $t4,0,exit_program
addi $t2,$t2,4
sw $t1, ($t2)
addi $t4,$t4,-1
beq $t4,0,exit_program
loop:
addi $t2,$t2,4
add $t5,$t0,$t1
addi $t5,$t5,1
sw $t5,($t2)
addi $t4,$t4,-1
beq $t4,0,exit_program
move $t0,$t1
move $t1,$t5
j loop
#display all elements
la $t2, array
lw $t0, N
li $t1,0
print_all: lw $a0, ($t2)
li $v0,1
syscall
addi $t2,$t2,4
beq $t1,$t0,exit_program
addi $t1,$t1,1
b print_all
exit_program:
li $v0, 10 # system call for exit
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.