MIPS汇编语言整数转ascii码的函数

本文介绍了如何在MIPS汇编语言中将整数转换为ASCII码字符串,提供了详细的函数代码,并解释了参数调整的原因。转换过程中需根据整数的最大位数来分配内存空间,确保不会影响其他字符串。使用时将待转换的整数放入$t0寄存器,通过jal指令调用函数。此外,还提及了该函数的二进制输出和ASCII码转整数的孪生机型。
摘要由CSDN通过智能技术生成

在用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
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值