#Registers used:
# $a0 : For loading Syscall parameters like loading integer, string
# address
# $V0 : For intiating particular syscall and return values
# $a1 : used as a argument to quicksort subroutine
# $a2 : used as a argument to quicksort subroutine
# $s1 : End address of iput array also as pointer
# $s4,$t2 : Base Address of input array acts as pointer
# $s3 : used to restore the address back to $s2
.text la $a0,String1 # enter address into a0 register to print String1 string li $v0,4 # printing msg syscall li $v0,5 #loading constant 5 into $v0 to read integer syscall move $a0,$v0 #scanned integer moving to $a0 sll $a0,$a0,2 #shifting bits left …show more content…
move $t0,$a0 #moving number of bytes into $t0 register li $v0,9 #loading 9 into $v0 to intialize array syscall add $t1,$t0,$v0 move $t2,$v0 #moving array address to $t2 move $s4,$t2 #moving array address to $s4 srl $t0,$t0,2 #reducing $t0 by shifting 2 locations
la $a0,String2 # enter address into a0 register to print String1 string li $v0,4 # printing msg syscall
addi $sp,$sp,-32 #allocate the stack with 32bytes sw $t0,28($sp) #store $to contents on stack sw $t1,24($sp) #store $t1 contents on stack sw $t2,20($sp) #store $t2 contents on …show more content…
$s3 (i ? n) #beq $t0, $zero, load1 # go to exit1 if $s0 ? $s3 (i ? n) subi $s1, $s0, 1 # j = i – 1 for2tst: slti $t0, $s1, 0 # $t0 = 1 if $s1 < 0 (j < 0) bne $t0, $zero, load2 # go to exit2 if $s1 < 0 (j < 0) sll $t1, $s1, 2 # $t1 = j * 4 add $t2, $s2, $t1 # $t2 = v + (j * 4) lw $t3, 0($t2) # $t3 = v[j] lw $t4, 4($t2) # $t4 = v[j + 1] slt $t0, $t4, $t3 # $t0 = 0 if $t4 ? $t3 beq $t0, $zero, load2 # go to exit2 if $t4 ? $t3 move $a0, $s2 # 1st param of swap is v (old $a0) move $a1, $s1 # 2nd param of swap is j j swap # call swap procedure
swap: sll $t1, $a1, 2 # $t1 = k * 4 add $t1, $a0, $t1 # $t1 = v+(k*4) # (address of v[k]) lw $t0, 0($t1) # $t0 (temp) = v[k] lw $t2, 4($t1) # $t2 = v[k+1] sw $t2, 0($t1) # v[k] = $t2 (v[k+1]) sw $t0, 4($t1) # v[k+1] = $t0 (temp) subi $s1, $s1,1 # j –= 1 j for2tst # jump to test of inner