快速排序mips(eclipse)/错误:没有可用的源

时间:2015-10-30 16:22:36

标签: eclipse debugging mips quicksort code-translation

我要从c程序转换为mips(使用eclipse,ubuntu)

在此过程中,我调试它。我遇到了

No source available for "QuickSort()"

,用于调试的光标停在

add $t1, $s0, $t2

然后去休息(); 我尝试用两个句子(加载$ s0然后添加)交换它,它没有用。

有人可以检查并更正我的程序吗?

我调查的mips程序 c程序中的data = numbers []

.globl QuickSort
QuickSort:
        beq $a1, $a2, QuickSortEnd
        nop
        addi $sp, $sp, -20
        sw $ra, 16($sp)
        sw $s3, 12($sp) #pivot
        sw $s2, 8($sp)  # right
        sw $s1, 4($sp)  # left
        sw $s0, 0($sp)  # data[]

        move $s2, $a2   #get right (move)
        move $s1, $a1   #get left (move)
        move $s0, $a0   #get data address (move)

        addi $t0, $a1, 1        # l_hold = left + 1
        add $t1, $a2, $zero     # r_hold = right

        sll $t2, $s1, 2         # $t2 = left*4
        add $t3, $s0, $t2       # $t3 = data + left*4 = data[left]
        lw $t4, 0($t3)          # load data[left]
        move $s3, $t4           # save it to pivot(s3)
while_1:
        slt $t4, $s1, $s2       #if left<right, t4=1
        beq $t4, $zero, Exit_while1 #if not (left<right), go to exit
while_in2:sll $t2, $s2, 2
        add $t3, $s0, $t2
        lw $t5, 0($t3)          # $t5 = data[right]
        slt $t2, $t5, $s3       # num[right] >=pivot -> t2=0
        slt $t3, $s1, $s2       # left<right    -> t3=1
        addi $t3, $t3, -1
        bne $t2, $t3, If1       #(numbers[right] >= pivot) && (left < right)
        addi $s2, $s2, -1       # right--
        nop
        j while_in2             # loop
If1:    beq $s2, $s1, While_in3
        nop
        sll $t2, $s1, 2
        add $t3, $s0, $t2       # data[left]
        sll $t5, $s2, 2
        add $t6, $s0, $t5
        lw $t7, 0($t6)          # t7 = data[right]
        sw $t7, 0($t3)          # data[left] = data[right]
        addi $s1, $s1, 1        # left++
While_in3:sll $t2, $s2, 2
        add $t3, $s0, $t2
        lw $t2, 0($t3)          # $t2 = data[left]
        slt $t4, $s3, $t2       # pivot < num[left] : 1
        slt $t5, $s1, $s2
        addi $t5,$t5, -1
        bne $t4, $t5, If2
        nop
        addi $s1, $s1, 1        # left++
        nop
        j While_in3
If2:    beq $s2, $s1, Exit_If2
        nop
        sll $t2, $s1, 2
        add $t3, $s0, $t2
        lw $t4, 0($t3)          # t4= data[left]
        sll $t5, $s2, 2
        add $t6, $s0, $t5       # data[right]
        sw $t4, 0($t6)          # data[right] = data[left]
        addi $s2, $s2, -1       # right--
        nop
Exit_If2:j while_1
Exit_while1:
        sll $t2, $s1, 2
        add $t3, $s0, $t2       # data[left]
        sw $s3, 0($t3)          # data[left] = pivot
        lw $t4, 4($sp)
        sw $t4, 12($sp)         # pivot = left
        sw $t0, 4($sp)          # left = l_hold
        sw $t1, 8($sp)          # right = r_hold
lastIf1:bge $s1, $s3, lastIf2
        addi $a2, $s3, -1       #right= pivot-1
        nop
        jal QuickSort
lastIf2:bge $s3, $s2, QuickSortEnd
        addi $a1, $s3, 1
        nop
        jal QuickSort
QuickSortEnd:lw $s0, 0($sp)     # restore $s0 from stack
        lw $s1, 4($sp)      # restore $s1 from stack
        lw $s2, 8($sp)      # restore $s2 from stack
        lw $s3,12($sp)      # restore $s3 from stack
        lw $ra,16($sp)      # restore $ra from stack
        addi $sp,$sp, 20    # restore stack pointer
        jr $ra

快速排序的原始C程序(参考:维基百科,韩国)

 /* void quickSort(int numbers[], int array_size)
 {
   q_sort(numbers, 0, array_size - 1);
 }

 void q_sort(int numbers[], int left, int right)
 {
   if(left == right) return;
   int pivot, l_hold, r_hold;
   l_hold = left+1;
   r_hold = right;
   pivot = numbers[left];

   while (left < right)
   {
     while ((numbers[right] >= pivot) && (left < right))
       right--;

     if (left != right)
     {
       numbers[left] = numbers[right];
       left++;
     }

     while ((numbers[left] <= pivot) && (left < right))
       left++;

     if (left != right)
     {
       numbers[right] = numbers[left];
       right--;
     }
   }

   numbers[left] = pivot;
   pivot = left;
   left = l_hold;
   right = r_hold;

   if (left < pivot)
     q_sort(numbers, left, pivot-1);
   if (right > pivot)
     q_sort(numbers, pivot+1, right);
 }*/

0 个答案:

没有答案