Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: Write a MIPS Assembly program to sort an array of numbers. The array should have minimum 10 numbers and can be initialized as shown

Objective: Write a MIPS Assembly program to sort an array of numbers. The array should have minimum 10 numbers and can be initialized as shown in the demo program.

Please fill in the code and give an explanation:

##Project 2: sorting an array of numbers ## FILL IN THE BLANKS to complete the project ## .data list1: .word 1, 55, 20, 7, 11, 0, 2, -1, 10, 45 str1: .asciiz " Before sorting " str2: .asciiz " After sorting: " space: .asciiz " " size: .word ## FILL ## .text main: la $a1, list1 lw $a2, size # print the unsorted array print_list1: #print string la $a0, str1 ## FILL ## syscall move $t1, $a1 li $t2, 0 move $t3, $a2 printing_loop1: beq $t2, $t3, exit lw $a0,($t1) li $v0, 1 syscall ## FILL ## li $v0, 4 syscall addi $t2, $t2, 1 #update loop counter addi $t1, $t1, 4 #update address ## FILL ## exit: move $t1, $a1 li $t2, 1 move $t3, $a2 #sort numbers sort_list: beq $t2, $t3, print_list2 #check if done lw $s0, 0($t1)#read list[0] into $s0 lw $s1, 4($t1)#read list[1] into $s1 blt $s0, $s1, continue #if a[0] < a[1], continue, else swap using $s5 as temporary variable #swap numbers move $s5, $s0 move $s0, $s1 move $s1, $s5 #update the list after swap sw $s0, 0($t1) #write to array sw $s1, 4($t1) #write to array li $t2, 0 move $t1, $a1 ## FILL ## continue: #update counter by 1 and address by 4 addi $t2, $t2, 1 ## FILL ## j sort_list # print the sorted array print_list2: la $a0, str2 li $v0,4 ## FILL ## lw $a0, size move $t1, $a1 li $t2, 0 move $t3, $a2 printing_loop2: beq $t2, $t3, last lw $a0,($t1) li $v0, 1 syscall la $a0, space li $v0, 4 syscall #update counter by 1 and address by 4 ## FILL ## ## FILL ## j printing_loop2 #exit program after printing the sorted array last: ## FILL ## syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Explain the characteristics of an effective appraisal system.

Answered: 1 week ago