以mips读取和打印整数 [英] Reading and printing an integer in mips

查看:917
本文介绍了以mips读取和打印整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序假设读取一个整数并将其打印回用户,但无论输入什么,每次只打印268501230。任何帮助将不胜感激。

My program is suppose to read an integer and print it back to the user but every time it just prints 268501230 no matter what is entered. Any help would be appreciated.

.data
prompt2: .asciiz "Please enter value: "
array1: .space 40
array2: .space 40
buffer: .space 4
.text

main: 

#Prints the prompt2 string
li $v0, 4
la $a0, prompt2 
syscall 

#reads one integer from user and saves in t0
li $v0, 5
la $t0, buffer
syscall

li $v0, 1       
li $t0, 5       # $integer to print
syscall         

exitProgram:    li $v0, 10  # system call to
    syscall         # terminate program


推荐答案

#reads one integer from user and saves in t0
li $v0, 5
la $t0, buffer
syscall

这不是系统调用5的工作方式。整数在 $ v0 中返回,因此代码应该类似于:

That's not how syscall 5 works. The integer is returned in $v0, so the code ought to be something like:

li $v0,5
syscall
move $t0,$v0







li $v0, 1       
li $t0, 5       # $integer to print
syscall 

您在这里也使用了错误的寄存器。要打印的整数应该进入 $ a0 ,而不是 $ t0

You're using the wrong register here as well. The integer to print should go into $a0, not $t0.

这是系统调用列表及其使用的寄存器

这篇关于以mips读取和打印整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆