Optimization code written in assembly DLX

I have this bubblesort in assembly, how can i optimize it?

;r1 = i
;r2 = num
;r3 = j
;r4 = punt[i]
;r5 = punt[j]
;r6 = temp
;r7 = num-1

ADDI r2, r0, 20 ;r2=num*4
SUBI r7, r2, 4

ADDI r1, r0, 0 ;i=0

while1:

ADDI r3, r1, 4 ;j=i+1


while2:

ADD r15, r15, r1
LW r4, 0(r15) ;punt[i]
SUB r15, r15, r1
ADD r15, r15, r3
LW r5, 0(r15) ;punt[j]
SUB r15, r15, r3
SLT r30, r4, r5
ADD r6, r0, r4 ;temp=p[i]
BNEZ r30, incr
;if

ADD r4, r0, r5 ;r4=r5
ADD r5, r0, r6 ;p[j]=temp
ADD r15, r15, r1
SW 0(r15), r4 ;punt[i]
SUB r15, r15, r1
ADD r15, r15, r3
SW 0(r15), r5 ;punt[j]
SUB r15, r15, r3
incr:

ADDI r3, r3, 4 ;j++
SLT r30, r3, r2 ;j<num
LW r16, 0(r15)
BNEZ r30, while2

ADDI r1, r1, 4 ;i++
SLT r30, r1, r7 ;i<num-1
BNEZ r30, while1
TRAP 0
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories