. I have an assignment in assembly MIPS ( i'm not asking for spoon feeding or to make some1 else to do my homework just some tips and suggestions).Assignment : Write a procedure (itoa) in assembly MIPS, that converts an integer to a null-terminated ASCII String. Procedure has as arguments in $a0 the integer and in $a1 a pointer to the memory where you should save the string that you produce. Procedure saves in $v0 the number of chars of string (expect the null).
My Solution:
Code:
itoa:
addi $t0,$zero,10 # t0=10
addi $t1,$t1,a0 # t1=a0
Loop:
div $t1,$t0 #t1/10
mflo $t1 #t1 = quotient
mfhi $t2 #t2 =remainder
addi $t2,$t2,0x30 #Convert to ASCII
addi $sp,$sp,-1 #Make space for 1 byte in the stack
sb $t2,0($sp) #Push t2 in the stack
addi $v0,$v0,1 #v0=v0+1
bne $t1,$zero,Loop #If t1<>0 go to Loop
order:
sw $t0,$v0 #t0=v0
lb $t1,0($sp) #pop the last byte for the stack
addi $sp,$sp,1 #Reduce the stack size by 1 byte
add $t2,$v0,-$t0 #t2=v0-t0
sb $t1,$t2($a1) # savebyte to the proper location of memory
addi $t0,$t0,-1 #t0=t0-1
bne $to,$zero,order #If t0<>0 go to order
sb 0x0,$v($a0) # add null character to the end of the string
jr $ra
