Question: Hello, I currently implemented the MIPS code to print out user given integers in reverse. However, I was wondering how I can add another method

Hello, I currently implemented the MIPS code to print out user given integers in reverse. However, I was wondering how I can add another method so that the user may enter a integer, n , under 20 so that n number of integers are printed per line based on the user inputted integers

.data

array: .space 80 #20 integers 4 bytes each

Enter: .asciiz " " #Skip a line

Prompt: .asciiz " Enter an integer: "

Prompt2: .asciiz " The integers you entered will print all in one line but in reverse! "

Prompt3: .asciiz " Enter the number of elements you want to see per line. "

Greet: .asciiz " You are about to enter 20 integers, get ready! "

space: .asciiz " " #literally a space

.text

main:

la $t4, space

la $t5, Enter

li $t0,20 #Register will be used as a iterator to keep track of ints.

la $t1,array #Load address of array

la $a0,Greet #Display Greeting Message

li $v0,4

syscall

loop: #loop for entering data

la $a0,Prompt #Display prompt

li $v0,4

syscall

li $v0,5 #Reading int

syscall

sw $v0,0($t1) #Store user input

add $t0,$t0,-1 #Iterator decrement

add $t1,$t1,4 # load the address of the next integer

bgtz $t0,loop # branch to read and store the next integer

addi $t1,$t1,-80 # so that we can start back from beginning at $t1,0

li $t3,20 # initialize printing counter

disp:

la $a0,Prompt2 #Display prompt

li $v0,4

syscall

loopS:

lw $a0, 0($t1) # now we print value at 0 of current t1

li $v0,1 # get ready to pring

#avoid the sysco

move $a0,$t4 # move space to a0

li $v0,4 # get ready to print space

#load but no syscall

addi $t1,$t1,4 # update t1 register's address by 4

addi $t3,$t3,-1 # decrement counter

bgtz $t3, loopS # repeat until counter equals 0

addi $t1,$t1,-4 # decrementing since pointer get 4 bytes ahead, so -4 will being it back to "20"

li $t3,20 # since we used up the counter initialize the $t3 value back to 20

move $a0,$t5 # move Enter to a0

li $v0,4 # get ready to print newLine. Printing new line just so loopT gets fresh new line for printing

syscall

loopT:

lw $a0, 0($t1) # now we print value at 0 of current t1

li $v0,1 # get ready to print

syscall # print 1st integer

move $a0,$t4 # move space to a0

li $v0,4 # get ready to print space

syscall # print space

addi $t1,$t1,-4 # update t1 register's address by 4

addi $t3,$t3,-1 # decrement counter

bgtz $t3, loopT # repeat until counter equals 0

addi $t1,$t1,4 # since we moved 4 bytes back to array starting point, this will point to first element in #array at $t1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!