Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- ############################## DATA SECTION ###################################
- ###############################################################################
- .data
- datalen:
- .word 0x0010 # 16
- data:
- .word 0xffff7e81
- .word 0x00000001
- .word 0x00000002
- .word 0xffff0001
- .word 0x00000000
- .word 0x00000001
- .word 0xffffffff
- .word 0x00000000
- .word 0xe3456687
- .word 0xa001aa88
- .word 0xf0e159ea
- .word 0x9152137b
- .word 0xaab385a1
- .word 0x31093c54
- .word 0x42102f37
- .word 0x00ee655b
- .word 0,0 # padding.... This shoulrd not be needed...
- .data
- newline:
- .word 0x0a
- ###############################################################################
- ############################# PROGRAM SECTION #################################
- ###############################################################################
- .text
- main:
- ##
- # $s1 addres to data arry
- # $s2 data arry length
- #
- # $s3 inner loop itterator -- i
- # $s4 outer loop itterator -- j
- #
- # $s5 indexOfLastLowValue
- # $s6 lastLowValue
- #
- # $t9 innerloop slt -- set to one if innerloop has reached the end.
- # Do Not Change...
- # $t8 outerloop slt -- set to one if outerlaap has reached the end.
- # Do Not Change...
- la $s1, data # addres to data
- lw $s2, datalen # datalen
- nop
- addi $s2, $s2, -1 # WHY?!?!?!?
- ######## Print the array before sortig
- printa:
- slt $t9, $s2, $s3
- seq $t9, $s2, $s3
- nop
- # print number
- sll $t3, $s3, 2
- add $t3, $t3, $s1
- nop
- lw $a0, ($t3)
- li $v0, 1
- nop
- syscall
- nop
- # print newline
- la $a0, newline
- li $v0, 4
- nop
- syscall
- nop
- addi $s3, $s3 ,1
- beqz $t9, printa
- nop
- add $t9, $zero, $zero
- # print newline
- la $a0, newline
- li $v0, 4
- nop
- syscall
- nop
- ############# END Print the array before sortig
- add $s3, $zero, $zero # i
- add $s4, $zero, $zero # j
- add $s5, $zero, $zero # indexOfLastLow
- add $s6, $zero, $zero # lastLowValue
- add $t9, $zero, $zero # set to one if i >= datalen
- add $t8, $zero, $zero # set to one if j >= datalen
- outerloop:
- seq $t9, $s2, $s3
- slt $t9, $s2, $s3 # if datalen < i
- # j = i + 1
- addi $s4, $s3, 1
- # indexOfLastLow = i
- add $s5, $s3, $zero
- # lastLowValue = data[i]
- sll $t4, $s3, 2 # t4 = t4 * 4 -- so it becames a word counter
- nop
- add $t4, $t4, $s1 # t4 = t4 + *data -- so that t4 poins to the
- nop # address of the element
- lw $s6, ($t4) # load the element into lastLowValue
- innerloop:
- seq $t8, $s2, $s4
- slt $t8, $s2, $s4 # if datalen < j
- # if array[j] < lastLowValue
- sll $t5, $s4, 2
- nop
- add $t5, $t5, $s1
- nop
- lw $t5, ($t5)
- nop
- blt $s6, $t5, endinnerloop # if lastLowValue is bigger then data[j]
- nop
- add $s6, $t5, $zero
- add $s5, $s4, $zero
- nop
- endinnerloop:
- # jump to innerloop if datalen >= j
- addi $s4, $s4, 1
- beqz $t8 innerloop
- nop
- # end of innerloop
- #### Swap elements
- nop
- # reset j
- add $s4, $zero, $zero
- nop
- #loads data[i]
- sll $t7, $s3, 2
- add $t7, $s1, $t7
- lw $t5, ($t7)
- nop
- # loads data[inderOfLastLow]
- sll $t3, $s5, 2
- nop
- add $t3, $s1, $t3
- nop
- lw $t6, ($t3)
- nop
- # Does the swap
- sw $t5, ($t3)
- sw $t6, ($t7)
- nop
- ### end swap elements
- # Reset j
- add $s4, $zero, $zero
- addi $s3, $s3, 1
- nop
- # jump back
- beqz $t9, outerloop
- ##### end of outerloop
- nop
- add $s3, $zero, $zero
- add $t9, $zero, $zero
- nop
- #Print the sortetd array
- print:
- seq $t9, $s2, $s3
- slt $t9, $s2, $s3
- nop
- # print number
- sll $t3, $s3, 2
- add $t3, $t3, $s1
- nop
- lw $a0, ($t3)
- li $v0, 1
- nop
- syscall
- nop
- # print newline
- la $a0, newline
- li $v0, 4
- nop
- syscall
- nop
- addi $s3, $s3 ,1
- beqz $t9, print
- nop
- exit:
- li $v0, 10
- syscall
- nop
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement