assembly - MIPS Quicksort program showing Exception 4 [Address Error in inst/data fetch ] -
i learning mips . tried write program on quicksort (without recursion). wrote following code . takes sorted array number of elements , number search input , returns array index of number ,
.data .align 2 myarray: .space 4000 #1000 elements atmost prompt1: .asciiz "enter n : " prompt2: .asciiz " " prompt3: .asciiz "\nenter sorted array: " prompt4: .asciiz "enter number sorted" .text main: li $v0, 4 la $a0, prompt1 syscall li $v0, 5 syscall move $s1, $v0, #n addi $s0, $s1, -1 li $v0, 4 la $a0, prompt4 syscall li $v0, 5 syscall move $s2, $v0 #stores k , number searched addi $t0, $zero, 0 #clear values in $t0 li $v0, 4 la $a0, prompt3 syscall input: li $v0, 5 # reading inputs syscall add $t1, $t0, $zero add $t3, $v0, $zero sll $t1, $t0, 2 sw $t3, myarray($t1) addi $t0, $t0, 1 slt $t1, $s0, $t0 beq $t1, $zero, input addi $t0, $zero, 0 # $t0 stores left sll $t1, $s0, 2 #t1 stores right add $t2, $t1, $t0 srl $t2, $t2, 1 # $t2 stores mid binsearch: bge $t0, $t1 , exit lw $t6, myarray($t2) #showing error here blt $t6, $s2, leftindex # if(a[mid]<k) goto left beq $t6, $s2, found bgt $t6, $t2, rightindex leftindex: addi $t0, $t2, 1 # left index leftindex= mid + 1 add $t2, $t1, $t0 # mid = left + right srl $t2, $t2, 1 # mid/2 j binsearch #goback binary search found: li $v0, 1 #if(a[leftindex]==k) addi $a0, $t0, 0 #print index of k syscall j exit #exit programme rightindex: addi $t1, $t2, -1 #rightindex = mid -1 add $t2, $t1, $t0 #mid = left+right srl $t2, $t2, 1 #mid/2 j binsearch #goback binarysearch exit: li $v0, 10 syscall
it giving me error : exception 4 [adderess error in inst/data fetch ]
it giving me error in line 70-72
lw $t6, myarray($t2) blt $t6, $s2, leftindex
i have mentioned line comment in code also
please tell me doing wrong .
Comments
Post a Comment