简体   繁体   中英

Mips code : loop error

I am working on mips for the 1st time

but my code seems to be stuck in an infinite while loop, I cant understand the problem. when I run my code in Qtspim it gives no errors and displays nothing and the window stops responding: little help would be appreciated! Thanks

.data
arr1:.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

.text
.globl _start
main:

add $s2,$zero,$zero
add $s3,$zero,$zero
add $t3,$zero,$zero
add $t4,$zero,$zero
add $s1,$zero,$zero

addi $t5,$zero,31
addi $t6,$zero,-1
addi $s0,$zero,12       # s0 = 12
add $t0,$s0,$zero       #initializing t0 with s0
addi $t2,$zero,2
while:

    slt $t1,$zero,$t0   #initialization (0<t0)
    beq $t1,$zero,while_exit#if(t1==0){exit}

    div $s0,$t2         # s0/2;
    mfhi $s1        # reminder
    mflo $t0        # answer of division    

    #add $t5,$t5,$t6        # sub

    beq $s1,0,else      #if(s1!=0){else}
    addi $s2,$s2,1      #counting no of ones
    addi $v0,$zero,1
    add $a0,$s1,$zero
    syscall
j while
else: 
    addi $s3,$s3,1      #counting no of zeros
    addi $v0,$zero,1
    add $a0,$s1,$zero
    syscall
j while 

while_exit:


addi $v0,$zero,10
syscall

You use $s0 for the dividend in each iteration, but $s0 never gets modified.

Nothing may be appearing in the output because you never finished a line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM