I wrote code to sort an Array using the bubble sort method. The dynamic Instruction is really long about 60k, i need to reduce it to about 20k. Could someone help me optimize the code or give me tips on how to do that? Or if there is a better algorithm? Thanks

.data
Array:  .alloc	100
.text

Sort:		addi	$1, $0, Array		
		swi	542			
loop1:		addi 	$2, $1, 396		
		addi	$3, $0,  0 		
loop2:		lw 	$5, 0($2) 		
		lw	$6, -4($2)		
		slt	$4, $5, $6		
		beq   	$4, $0, skip		
		sw 	$6, 0($2) 		
		sw	$5, -4($2)		
		addi	$3, $0, 1		
skip:		addi	$2, $2, -4		
		bne	$2, $1, loop2		
		bne	$3, $0, loop1		
		jr 	$31

oh and i cant have more than 17 static instructions. A little more than that would be too bad if it get rid of the excess dynamic Inst. problem

What do you mean by "static" and "dynamic" instructions?

I don't see anything there worth 60,000 bytes.

I also don't know how you could make a bubble sort any smaller...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.