itoa procedure (assembly MIPS)

Discussion in 'Assembly Language Programming (ALP) Forum' started by UnSourCeR, Dec 25, 2011.

1. UnSourCeRNew Member

Joined:
Dec 25, 2011
Messages:
2
0
Trophy Points:
0
Occupation:
University Student
Location:
Athens
http://www.prosweb.gr
Hello, that's my 1st post in your forum . 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:
Loop:
div \$t1,\$t0    #t1/10
mflo \$t1      #t1 = quotient
mfhi \$t2      #t2 =remainder
addi \$sp,\$sp,-1 #Make space for 1 byte in the stack
sb \$t2,0(\$sp) #Push t2 in the stack
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
sb \$t1,\$t2(\$a1) # savebyte to the proper location of memory
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```
Soz for my bad english, is this solution right? Do you have any tips for simpler code?Thanks in advance

Joined:
Dec 25, 2011
Messages:
2