Hello, I need help with creating a bubble sort code of 24 instructions in MIPS l
ID: 3766217 • Letter: H
Question
Hello, I need help with creating a bubble sort code of 24 instructions in MIPS language.
My full assignment is this:
The goal of this project is to test your ability to write and optimize PLP programs. You will be given skeleton code, which has a call to a sorting function, which you will need to implement. This sorting function will be an implementation of the bubble sort algorithm and needs to perform an in-place sort on an array in memory. You will be awarded 1 extra credit point for your program if it contains fewer than 24 of instruction (comments, labels, and white space don’t count as instructions) or is able to complete the all of the arrays used for grading in fewer than 120,000 cycles.
Much appreciation in advance.
Explanation / Answer
main :
li $v0,4
la $a0,header
syscall
BeforePrint:
li $v0,4
la $a0,before
syscall
jal PrintArray
Sort:
jal Bubble
AfterPrint:
li $v0,4
la $a0,endl
syscall
syscall
la $a0,after
syscall
jal PrintArray
li $v0,4
la $a0,exitMsg
syscall
li $v0,10
syscall
.end
.text
.ent PrintArray
li $t1,0
li $t2,32
print_begin:
li $v0,1
lw $a0,array($t1)
syscall
li $v0,4
la $a0,blanks
syscall
addi $t1,$t1,4
blt $t1,$t2,print_begin
print_end:
end_line:
li $v0,4
la $a0,endl
j $ra
.end
.text
.ent bubble
Bubble:
li $t7,36
li $t1,8
outer:
lw $t0,array($0)
sub $t4,$t7,$t1
li $t2,0
inner:
addi $t3,$t2,4
if:
lw $t6,array($t3)
blt $t0,$t6,else
then:
sw $t6,array($t2)
b endif
else:
sw $t0,array($t2)
lw $t0,array($t3)
endif:
addi $t2,$t2,4
blt $t2,$t4,inner
inner_end:
sw $t0,array($t4)
addi $t1,$t1,4
blt $t1,$t7,outer
outer_end:
j $ra
.end
.end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.