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

MARS MIPS Program that Sorts Arrays Write a MIPS program to complete the followi

ID: 441839 • Letter: M

Question

MARS MIPS Program that Sorts Arrays Write a MIPS program to complete the following functions. You must write comments and follow the register convention. [30 points] (1) Declare an integer array of 20 elements and other variables and labels; [5] (2) Write a procedure to initialize the array. Use random numbers between 0 and 99, and use a loop to initialize the array. [10] (3) Implement a sort procedure. You can use the sort procedure given in textbook 2.1.3. [5] (4) Write the main program. It calls the initialization procedure; prints the numbers in the array; calls the sort procedure to sort the numbers in the array; and print the numbers in the sorted array. [10] Based on the syscalls in MARS simulator, you can use the following code to generate random numbers between 0 and 99. li $a1,100 # define the upper range li $v0, 42 # 42 is the syscall code for random integer generation syscall # the generated random number will be placed in $a0

Explanation / Answer

.data .align 4 Table: .space 24 msg1: .asciiz "Please insert an integer: " msg2: .asciiz " " msg3: .asciiz " Vector contents: " .text .globl main main: addi $s0,$zero,5 addi $t0,$zero,0 in: li $v0,4 la $a0,msg1 syscall li $v0,5 syscall add $t1,$t0,$zero sll $t1,$t0,2 add $t3,$v0,$zero sw $t3,Table ( $t1 ) addi $t0,$t0,1 slt $t1,$s0,$t0 beq $t1,$zero,in la $a0,Table addi $a1,$s0,1 #a1=6 #call buble_sort jal buble_sort #print table li $v0,4 la $a0,msg3 syscall la $t0,Table #s0=5 add $t1,$zero,$zero printtable: lw $a0,0($t0) li $v0,1 syscall li $v0,4 la $a0,msg2 syscall addi $t0,$t0,4 addi $t1,$t1,1 slt $t2,$s0,$t1 beq $t2,$zero,printtable li $v0,10 syscall buble_sort: #a0=address of table #a1=sizeof table add $t0,$zero,$zero #counter1( i )=0 loop1: addi $t0,$t0,1 #i++ bgt $t0,$a1,endloop1 #if t0