Mips 浮点排序

Mips 浮点排序,mips,bubble-sort,Mips,Bubble Sort,对于MIPS中的一个项目,我尝试使用冒泡排序从最小到最大对浮点数组进行排序。目前它给了我所有的零,我不确定我在下面的代码中哪里出了问题。另一个注意事项是,如果我取出该行: bne $a0, $t0, innerLoop 然后它将对前两个元素进行排序 .data FPNum: .word 0x0 max: .word 0 temp: .word 1 num: .space 100 inpu

对于MIPS中的一个项目,我尝试使用冒泡排序从最小到最大对浮点数组进行排序。目前它给了我所有的零,我不确定我在下面的代码中哪里出了问题。另一个注意事项是,如果我取出该行:

bne  $a0, $t0, innerLoop
然后它将对前两个元素进行排序

.data
FPNum:      .word 0x0
    max:            .word 0
    temp:           .word 1
    num:            .space 100
    input1:         .asciiz "Enter a number:\n" #prints the statement 
    output1:        .asciiz "The number that is repeated more often than any other is "
    output2:        .asciiz " with "
    output3:        .asciiz " repititions.\n"
    output4:        .asciiz "The array contains the following: \n"

.text   
main:
    lw     $t1, temp # loop counter
    lw     $t2, max  # upper bound
    la     $t0, num  # address of array
    lwc1   $f10, ($t0)  # $f10=0.0

Loop:
# print input prompt
    la     $a0, input1
li     $v0, 4     
    syscall

    # get value from the user
    li     $v0, 6
    syscall

c.eq.s $f0, $f10
    bc1t bubble_sort

# move user provided value from $f0 to array
    s.s    $f0, 0($t0)

    # move to the next position in the array, increment loop counters
    addi   $t0, $t0, 4
    addi   $t2, $t2, 1
    j Loop

 bubble_sort:
 la  $t0, num      # Copy the base address of your array into $t1
    add $t0, $t0, 40    # 4 bytes per int * 10 ints = 40 bytes                           
 outterLoop:             # Used to determine when we are done iterating over the Array
    add $t6, $0, $0     # $t1 holds a flag to determine when the list is sorted
    la  $a0, num      # Set $a0 to the base address of the Array
 innerLoop:                  # The inner loop will iterate over the Array checking if a swap is needed
    l.s  $f1, 0($a0)         # sets $f1 to the current element in array
    l.s  $f2, 4($a0)         # sets $f2 to the next element in array
    c.lt.s $f1, $f2          #  f if $f1 > $f2
    bc1t continue       
    addi $t6, $0, 1          # if we need to swap, we need to check the list again
    s.s  $f1, 4($a0)         # store the lesser numbers contents in the higher position in array (swap)
    s.s  $f2, 0($a0)         # store the higher numbers contents in the lower position in array (swap)
continue:
    addi $a0, $a0, 4            # advance the array to start at the next location from last time
    bne  $a0, $t0, innerLoop    # If $a0 != the end of Array, jump back to innerLoop
    bne  $t6, $0, outterLoop    # $t6 = 1, another pass is needed, jump back to outterLoop


  restore:
    # restore array address for printing
    la $t0, num
    lw $t1, temp

 # print output prompt
    la $a0, output4
    li $v0, 4
    syscall

 print_loop:
    # print number from the array
    l.s    $f12, 0($t0)
    li     $v0, 2
    syscall

    # print space
    la $a0, 32
    li $v0, 11
    syscall

    # increment loop counter and move to next value
    addi $t1, $t1, 1
    addi $t0, $t0, 4
    ble $t1, $t2, print_loop

当你一行一行地浏览代码时,第一行给出的结果是什么?(这很有帮助,我发现使用MARS比SPIM更容易一步一步地完成代码。)当你一行一行地完成代码时,第一行给出的结果是什么?(这很有帮助,我发现使用MARS单步执行代码比使用SPIM容易得多。)