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

* MIPSSYM* ASSEMBLY LANGUAGE ONLY Write a program to print out a series of numbe

ID: 3817334 • Letter: #

Question

* MIPSSYM* ASSEMBLY LANGUAGE 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

.data

   Prompt1: .asciiz " How many integers (20 or less) will you input? "
   Prompt2: .asciiz " Enter the integers : "
   A: .space 80 #Array A can store 20 integers (each 4 bytes)
   counter: .space 8
  
  

.text

main:

inputN:
   li $v0, 4
   la $a0,
   syscall
   li $v0, 5
   syscall
  
   move count, $v0
   bge count, 20, inputN

inputList:
   li $v0, 4
   la $a0,
   syscall

   li $v0, 5
   syscall

   move $t1, $v0
    move $a0,$t2
   move $v0,$t2
   jal series #call series
   move $t3,$v0   #store result in $t3
   print $t3
   sw $t1, A
   la $s1, A
   li count, 1
   addi count, count, 1
  
   ble $t0, count, inputList
  
   li $v0, 4
   la $a0, Output
   syscall

series:
   beqz $a0,zero #if n=0 return 2
   beq $a0,1,one #if n=1 return 4

sub $sp,$sp,4   
sw $ra,0($sp)

sub $a0,$a0,1   
jal series   
add $a0,$a0,1

lw $ra,0($sp)   
add $sp,$sp,4


sub $sp,$sp,4   
sw $v0,0($sp)

sub $sp,$sp,4   
sw $ra,0($sp)

sub $a0,$a0,2   
jal series #calling series
add $a0,$a0,2   #adding it to previously received values

lw $ra,0($sp)   
add $sp,$sp,4

lw $s7,0($sp)   
add $sp,$sp,4

add $v0,$v0,$s7
jr $ra
zero:
li $v0,2
jr $ra
one:
li $v0,4
ajr $ra

// The most important thing here is to maintain the addresses. While storing the return address on stack, you have to be careful that you don't miss out on any of the returned values.