对于我的作业,我需要使用MIPS在前面输入任意字母,然后输入数字(例如x123),然后在数字中加5,然后打印出最终数字(从该示例输出将是128)字符串到int转换和字符串操作MIPS
1
A
回答
0
。数据
entmsg:.asciiz “输入字符串:\ n” 个 UI1:20。空间计数器 :20。空间 outmsg:.asciiz“的值+5是:\ n“
.text main: #Printing消息 李$ V0,4 LA $ A0,entmsg 系统调用
#Saving the text
li $v0, 8
la $a0, ui1
li $a1, 20
syscall
#Count the length of the string
la $t0, ui1 # la means load address (so we load the address of str into $t0)
li $t3, 0 # $t1 is the counter. set it to 0
countChr:
磅$ T2,0($ T0)#负载从地址$在T0
的第一个字节 beqz $ t2,pot#if $ t2 == 0 then then to label end
add $ t0,$ t0,1#else increment the address
add $ t3,$ t3,1#and add the counter of course
j countChr#finally loop
锅:
li $t1, 1 # $t1 is the counter. set it to 1
li $t2, 0 #$t2 is the sum
sub $t3, $t3, $t1
getint:
LBU $ t0时,UI1($ T1)#负载从地址$在T0
BEQ $ T1,$ t3中,端#NULL终止的第一个字节发现 阿迪$ t0,$ t0,-48#将t1的ascii值转换为dec值 mul $ t2,$ t2,10 #sum * = 10 add $ t2,$ t2,$ t0 #sum + = array [s1] - '0 ' 阿迪$ T1,$ T1,1个#increment阵列地址 Ĵgetint#最后循环
#in the loop take the ascii value of the char and then convert it to an int and then add it to the answer
末: #将5号 阿迪$ T2,T2 $ 5
#print out second message and text
li $v0, 4
la $a0, outmsg
syscall
#Print out number
#Gets the right answer now I just need to be able to output it
li $v0, 1
add $a0, $zero, $t2
syscall
#Close program
li $v0, 10
syscall
这是所有的代码只是输入的东西是太多的努力得到它的正确格式
相关问题
- 1. 操作Python int /字符串
- 2. 转换INT [] []将字符串
- 3. 将int和char转换为字符串
- 4. 字符串到int数组转换c#
- 5. 从int到字符串的转换
- 6. 字符串到int转换的列表
- 7. 字符串到Int转换:Convert.toInt16
- 8. 转换字符串转换成int()
- 9. 从字符串到Clob和Clob到字符串的转换
- 10. 如何将字符串与int转换为字符串与双?
- 11. TFileStream和字符串操作
- 12. 简单的C++ - 关于字符串和级联和INT转换为字符串
- 13. 将字符串转换为字符串
- 14. 转换字符串[字符串:任何]
- 15. 将Uri转换为字符串和字符串到Uri
- 16. 无法将字符串转换为常量字符/字符串*为int *
- 17. 将字符串转换为int如果字符串中有其他字符
- 18. 字符串操作
- 19. 字符串操作
- 20. 字符串操作
- 21. 字符串操作
- 22. 字符串操作
- 23. 字符串操作
- 24. 字符串操作
- 25. 字符串操作?
- 26. 字符串操作
- 27. 字符串操作
- 28. 字符串操作
- 29. 字符串操作
- 30. 字符串操作
嗨,欢迎堆栈溢出。为了帮助您,我们需要查看一些代码,预期结果以及迄今的尝试。看看这个快速指南如何提出相关问题:https://stackoverflow.com/help/how-to-ask – Moseleyi