Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have to create an array size of N, and print the code in ascending order as a result in MIPS. I am having the

I have to create an array size of N, and print the code in ascending order as a result in MIPS. I am having the hardest time figuring out what I am doing wrong here. I have found similar questions that answer my question for an array size of 10 but I need to make my code work for size N. I have no idea where I went wrong or how to fix it so as a last resort I'm coming here. Any help/corrections are appreciated. (not all comments are accurate as I have changed/edited these numerous times without updated the comments yet. I have also destroyed this a bit trying to figure out what to do. Sorry this is a mess, I know someone can help.

.data array: .space 4000 arraySizePrompt: .asciiz "Enter Array Size: " arrayIntegerPrompt: .asciiz "Enter Integer: " whiteSpace: .asciiz " " sortedArrayPrompt: .asciiz "Sorted array: " .text li $v0,4 #load 4 into $v0 (print string) la $a0,arraySizePrompt #load arraySizePrompt text into $a0 syscall la $a1, array la $t5, array # Constant value # Gets integer from the user. This code triggers a system call li $v0, 5 # 5 indicates read integer system call syscall # Execute System Call add $t0, $zero, $v0 # put the results in $t0 add $t1, $t0, $zero arrayLoop: addi $t1, $t1, -1 # Gets integer from the user. This code triggers a system call li $v0,4 #load 4 into $v0 (print string) la $a0,arrayIntegerPrompt #load arrayIntegerPrompt text into $a0 syscall li $v0, 5 # 5 indicates read integer system call syscall # Execute System Call add $t2, $zero, $a1 # put the results in $t0 sw $t2, 0($a1) addi $a1, $a1, 4 beq $t1, $zero, exitArrayLoop # Exit loop when we fill array j arrayLoop exitArrayLoop: la $a1, array add $t1, $t0, $zero addi $t1, $t1, -1 bubbleSort: beqz $t1,exitBubbleSort #if $t1 is zero, goto here addi $t1,$t1,-1 #subtract 1 from $t1, save to $t1 lw $t6,0($a1) #load an input int into $t6 lw $t7,4($a1) #load the next one into $t7 addi $a1,$a1,4 #add 4 to $t5, save to $t5 ble $t6,$t7,bubbleSort #if $t5 <= $t6, goto bubbleSort sw $t6,0($a1) #else, store $t6 in $t5 sw $t7,-4($a1) #and store $t7 in $t5-4 (swapping them) bnez $t1,bubbleSort #if $t1 is not zero, to go bubbleSort exitBubbleSort: la $a1, array add $t1, $t0, $zero printArrayLoop: addi $t1, $t1, -1 lw $a0, 0($a1) li $v0, 1 syscall addi $a1, $a1, 4 beq $t1, $zero, exitPrint j printArrayLoop exitPrint: 

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

We insist that you always bring your credit card to the store.

Answered: 1 week ago