在用MIPS汇编语言编程时,有些情况下我们需要将整数转成字符串的形式操作,这里为大家提供了一个现成的函数,注释标的很详细,供大家使用。
上代码!
string: .space 4 #one more space, or the following string will be printed
toString: li $t2, 2 #the number of needed space -1. the number of digits won't exceed 3, so we only need 3 space.
la $t3, string #the last digit locates in ($t3+2), which is ($t3+$t2)
li $t5, 10
bgez $t0, notNeg1 #print without a '-'
nop
li $a0, '-'
li $v0, 11 #print $a0 ('-')
syscall
neg $t0, $t0 #to positive
notNeg1: div $t0, $t5 #divide 10
mflo $t0 #quotient
mfhi $t1 #remainder
addi $t1, $t1, 48 #the ascii of the remainder
add $t4, $t3, $t2 #get the store locatio