Hi I have been trying to implent this sorting algorithm for 100 ints.. I used the bubble sort one as well as quicksort...
I have spent nearly two weeks trying to code quicksort and gladly changed to bubble seen that qsort nearly gave me a nervous breakdown!
bubble sort is this:
Bubblesort (int data[],int n) {
int tmp,i,j;
for (i=0; i<n-1; i++) {
for (j=0; j<n-i-1; j++)
if (data[j] > data[j+1]) {
tmp = data[j];
data[j] = data[j+1];
data[j+1] = tmp;
}
}
}
and here is my implementation in bubblesort........
.data
array: .word 0x11,0x111,0x1111111,0x111
11,0x1,0x111111111,0x111111,0x111111111,0x111,0x11,0x1111,0x11111111,0x111,0x111111,0x111,0x11111111,0x111111111,0,0x1,0x1111111
.text
dadd r1, r0, r0 ;i
dadd r2, r0, r0 ;j
daddi r6, r2, 8 ;j+1
ld r3, array(r0)
dsll r3, r3, 3 ;n
daddi r7, r3, -8 ;n-1
label: slt r12 ,r1, r7 ;check i< n-1
beqz r12, done ;if not halt
dsub r13, r3, r1 ; else set up for j loop....(ie) n-i
daddi r14, r13, -8 ; n-i-1
here: slt r15, r2, r14 ; if !r2 < n-i-1
beqz r15,inci ; go to next i
ld r19, array(r2) ; else do the swap
ld r20, array(r6)
slt r21, r19, r20
bnez r21, incj
ld r18, array(r6)
ld r16, array(r2)
sd r16, array(r6)
sd r18, array(r2)
incj: daddi r2, r2, 8 ; next iteration of j
daddi r6, r2, 8
j here
inci: dadd r2, r0, r0 ; inc i and reset j and j+ 1
daddi r1, r1, 8
daddi r6, r2, 8
j label ; go again
done: halt
the thing is i have an application from that shows the stats of the reg and mem etc.. a kind of simulator! can be downloaded from here http://www.computing.dcu.ie/~mike/winmips64.html installs in seconds
but this sort is taking way to many clock cycles maybe it can be optimized better also it will not sort the last four of the array...please help