quicksort: sub $sp, $sp, 20 #making room on the stack #saving the contents of each saved register sw $s0, 16($sp) #s0 will be i sw $s1, 12($sp) #s1 will be j sw $s2, 8($sp) #s2 will be *x sw $s3, 4($sp) #s3 will be *t sw $ra, 0($sp) #saving the return address # x = a[(first + last) /2]; add $t0, $a1, $a2 #putting the sum of first and last into t0 sra $t0, $t0, 1 #dividing by 2 add $t1, $a0, $t0 #i = first; j = last; add $s0, $a1, $zero add $s1, $a2, $zero print_array: main: .data data_array: .align 5 .asciiz "Joe" .asciiz "Jenny" .asciiz "Jill" .asciiz "John" .asciiz "Jeff" .asciiz "Joyce" .asciiz "Jerry" .asciiz "Janice" .asciiz "Jake" .asciiz "Jonna" .asciiz "Jack" .asciiz "Jocelyn" .asciiz "Jessie" .asciiz "Jess" .asciiz "Janet" .asciiz "Jane" size: .word 16 str: .asciiz "Initial array is:\n" .text li $v0, 4 la $a0, str syscall print_array: .text la $s0, data print_loop: lw $t0, 0($s0) str_lt: sub $sp, $sp, 4 #making room on the stack sw $ra, 0($sp) #saving the return address lb $t0, 0($zero) #for (; *x!='\0' && *y!='\0'; x++, y++) loop: lb $t1, 0($a0) lb $t2, 0($a1) beq $a0, $t0, zero beq $a1, $t0, zero #if ( *x < *y) return 1; else 0 slt $t3, $a0, $a1 addi $a0, $a0, 4 #add 4 to a0 and a1 addi $a1, $a1, 4 bne $a0, $t0, loop one: addi $t3, $zero, 1 zero: add $t3, $t3, 0