Trying to make a 3 range partition in mips
I am trying to make a 3 range partition in mips32 and i am having some troubles. I am trying to make quicksort. With a swap,parition, and a quicksort function. I understand how to do swap and quicksort but i am not sure how to do the partition. I am confused it i use swap in my partition function and if i am even heading on the right path. Can someone please help me.

The three ranges are { all elements ≤ p } { all elements == p } { all elements ≥ p } 

p: pivot

Here is the code i have written so far:


    ##############################################
    ##              Swap Function               ##
    ##############################################
    # $t1 = i
    # $t2 = j
    # Address A[i] == $s0 + 4(St1) <===> $t3
    # Address A[j] == $s0 + 4(St2) <===> $t4
    # Value of A[i] <===> $t5
    # Value of A[i] <===> $t6

    swap:
                li $t1,0
                li $t2, 1023.
                
    swap_loop:
                slt $t3,$t1,2
                add $t2,$t3, $t0
                slt $t4,$t2,2
                add $t4,$t4,$s0
                lw $t5,0($t3)
                lw $t6,0($t4)
                sw $t5,0($t4)
                sw $t6,0($t3)
                addi $t1,$t1,1
                addi $t2, $t2,-1
                blt $t2,$t1,swap_exit
                j swap_loop
                
    swap_exit:


    ##############################################
    ##              Partition Function          ##
    ##############################################
    # int parition(Array,i,j)
    # {
    #	
    #	


    parition:
   		move $s1,$a1
		move $s2,$a2
		sll  $s3,$s1,2
		add $s3,$s3,$a0
		lw $s3, 0($s3)
		
    partition_empty:
		beq $s1,$s2,parition_exit
		sll $t3,$s2,2
		add $t3,$a0,$t3
		lw $t1,0($t3)

    partition_exit:


    ##############################################
    ##              Quicksort Function          ##
    ##############################################
Trying to make a 3 range partition in mips
===

I am trying to make a 3 range partition in mips32 and i am having some troubles. I am trying to make quicksort. With a swap,parition, and a quicksort function. I understand how to do swap and quicksort but i am not sure how to do the partition. I am confused it i use swap in my partition function and if i am even heading on the right path. Can someone please help me.

The three ranges are { all elements ≤ p } { all elements == p } { all elements ≥ p } 

p: pivot

Here is the code i have written so far:


    ##############################################
    ##              Swap Function               ##
    ##############################################
    # $t1 = i
    # $t2 = j
    # Address A[i] == $s0 + 4(St1) <===> $t3
    # Address A[j] == $s0 + 4(St2) <===> $t4
    # Value of A[i] <===> $t5
    # Value of A[i] <===> $t6

    swap:
                li $t1,0
                li $t2, 1023.
                
    swap_loop:
                slt $t3,$t1,2
                add $t2,$t3, $t0
                slt $t4,$t2,2
                add $t4,$t4,$s0
                lw $t5,0($t3)
                lw $t6,0($t4)
                sw $t5,0($t4)
                sw $t6,0($t3)
                addi $t1,$t1,1
                addi $t2, $t2,-1
                blt $t2,$t1,swap_exit
                j swap_loop
                
    swap_exit:


    ##############################################
    ##              Partition Function          ##
    ##############################################
    # int parition(Array,i,j)
    # {
    #	
    #	


    parition:
   		move $s1,$a1
		move $s2,$a2
		sll  $s3,$s1,2
		add $s3,$s3,$a0
		lw $s3, 0($s3)
		
    partition_empty:
		beq $s1,$s2,parition_exit
		sll $t3,$s2,2
		add $t3,$a0,$t3
		lw $t1,0($t3)

    partition_exit:


    ##############################################
    ##              Quicksort Function          ##
    ##############################################