MIPS阵列分配无限循环

时间:2018-04-24 00:40:03

标签: arrays assembly mips

我试图解决这个问题几个小时!!!!! 当我为数组输入8个整数然后输入0完成读数时,当循环部分开始时它进入无限循环! 我无法找到问题所在,当我从addiu数组中删除$s2时,它工作正常但不会将$t1存储在数组中!

请帮助!!

.data
array:  .space 32
percentage_Array: .space 32
newLine: .asciiz "\n"


.text
main:
        la $s1, array
        la $s2, percentage_Array

read_numbers:
        li $v0, 5
        syscall

        sw $v0, 0($s1)
        addiu $s1, $s1, 4

        beqz $v0, continue
        j read_numbers

continue:
        la $s1, array


loop:
        lw $t0, 0($s1)
        addiu $s1, $s1, 4

        beqz $t0, exit

        move $a1, $t0
        jal calculate_Ones_and_Bits

        move $s6, $v0
        move $s7, $v1

        #put the total number of ones
        add $s0, $s0, $s7 

        #calculate the percentage
        addi $t5, $zero, 100
        mult $s7, $t5
        mflo $t1
        div $t1, $s6
        mflo $t1

        #-----I THINK HERE IS MY PROBLEM------
        #Put the percentages on percentage_Array array
        sw $a1, 0($s2)
        addiu $s2, $s2, 4

        #Check which percentages are greater than 50 and print the numbers 
        which fulfill the condition
        slti $t2, $t1, 50
        beq $t2, 1, loop

        li $v0, 1
        move $a0, $t0
        syscall

        #lines 66,67,68 are extra just for printing in new line more clearly
        li $v0, 4
        la $a0, newLine
        syscall

        j loop

exit:
        #lines 73,74,75 are also extra just to print the value of s0, it is 
        printed here so it
        #will be executed after the loop has finished
        li $v0, 1
        move $a0, $s0
        syscall

        #tell the OS to exit/finish
        li $v0, 10
        syscall

0 个答案:

没有答案