ambinh 0 Newbie Poster

Hi I am testing this function itoa, but I got infinite loop. Could anyone help me to fix this? Here is my code

Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

.data
result_str: .asciiz "            "      #reserve 12 spaces
prompt: .asciiz "Enter a string number: "
answer: .asciiz "\nConverted string: "

.text

main:
    la $a0, prompt
    li $v0, 4
    syscall

    li $v0, 5
    syscall

    addi $t0, $zero, 10     #save 10 to $t0
    move $t1, $v0       #move value in $v0 to $t0

loop:
    blt $t1, $zero, end
    divu $t1, $t0       #divide the number in $t1 by 10
    mflo $t1        #set quotion to $t0 for relooping
    mfhi $t2        #set remainder to $t2
    addu $t2, $t2, 48   #convert to ascii character
    sb $t2, result_str
    sub $t0, $t0, 1

    b loop
end:
    move $t0, $v0
    la $v0, result_str
    li $v0, 4
    syscall

    li $v0, 10
    syscall
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.