Professional Documents
Culture Documents
text
main:
#printing welcome message
la $a0, welcome
li $v0, 4
syscall
enterSize:
li $v0, 5
syscall
notNegative:
la $a0, cannotBeNegative
li $v0, 4
syscall
j enterSize
validSize:
#creating array
sw $v0, arraySize
move $t0, $v0
mul $t0, $t0, 4
sw $v0, arrayAddress
jal monitor
monitor:
loopMonitor:
doneMonitor:
displayArray:
loopDisplay:
printComma:
la $a0, comma
li $v0, 4
syscall
commaPrinted:
doneDisplay:
jr $ra
displayMenu:
#printing menu
la $a0, welcomeToMenu
li $v0, 4
syscall
la $a0, enterToSort
li $v0, 4
syscall
la $a0, enterToMaxMin
li $v0, 4
syscall
la $a0, enterToQuit
li $v0, 4
syscall
li $v0, 5
syscall
bubbleSortJAL:
jal bubbleSort
jal displayArray
j enterSize
minMaxJAL:
jal minMax
j enterSize
bubbleSort:
loopSort:
nextLoop:
nextLoopDone:
lw $t0, 0($s1) #register t0 holds element on the smaller array
index
lw $t1, 0($s2) #register t1 holds element on the bigger array
index
swap:
swapDone:
sortDone:
jr $ra
minMax:
setLess:
setLessDone:
setGreater:
setGreaterDone:
minMaxDone:
la $a0, minVal
li $v0, 4
syscall
la $a0, maxVal
li $v0, 4
syscall
quit:
la $a0, goodbye
li $v0, 4
syscall
li $v0, 10
syscall
.data
arraySize:
.word 0
arrayAddress:
.word 0
welcome:
.asciiz "Welcome!\n"
enterArrSize:
.asciiz "\nPlease enter an array size(0 to quit): "
enterElem:
.asciiz "\nEnter elements to add to the array: "
printArray:
.asciiz "Array: "
comma:
.asciiz ", "
welcomeToMenu:
.asciiz "\n---------------Welcome to the menu---------------\n"
enterToSort:
.asciiz "1) Sort the array using bubble sort\n"
enterToMaxMin:
.asciiz "2) Find maximum and minimum values in the array\n"
enterToQuit:
.asciiz "3) Quit\n"
yourChoice:
.asciiz "Your choice: "
invalidChoice:
.asciiz "Invalid option! Enter again\n"
goodbye:
.asciiz "Goodbye!"
arraySorted:
.asciiz "Your array has been sorted!\n"
foundMinMax:
.asciiz "Minimum and meximum elements are found!\n"
minVal:
.asciiz "Minimum: "
maxVal:
.asciiz "\nMaximum: "
cannotBeNegative:
.asciiz "Size cannot be negative! Enter again\n"