铸造在MIPS [英] Casting in MIPS

查看:162
本文介绍了铸造在MIPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的问题!

我实现了一个记忆游戏MIPS,
游戏通过在屏幕上随机打印10-99之间的数字开始,
然后要求用户输入的确切人数。如果用户正确地输入数字,游戏通过显示第一数目和10-99之间的第二随机产生的数继续。和这两个数必须显示一个接一个,它们之间有3秒的延迟。用户随后被要求以正确的顺序输入数字,因为他们出现在屏幕上。如果用户输入的两个数字正确比赛继续与三个数字,然后四等。

I implemented a memorizing game in MIPS, The game starts by randomly printing a number between 10-99 on the screen, then ask the user to enter the exact number. If the user enters the number correctly, the game continues by displaying the first number and a second randomly generated number between 10-99. and the two numbers have to displayed one after another with a 3 second delay between them. The users is then is asked to enter the numbers in the correct order as they appeared on the screen. If the user enters the two numbers correctly the game continues with three numbers, then four and so on.

这是一个快速夏日的游戏,但这里是的东西。

this is a quick summery for the game , but here is the thing.

我想补充的助手选项,如果用户输入的字母H,该计划给他一个暗示。

I want to add an assistant option that if the user entered the letter 'H' , the program give him a hint.

我用这个来获得,是以数字用户输入

I used this to get the input from the user that takes the numbers

李$ v0,5

系统调用

这个读整,但一旦用户输入H它给出了一个运行时错误,

this 'read an integer' but once the user enter an 'H' it gives a run time error,

我虽然这'H'的值是:72 ASCII
我把它作为用户使用作为一个提示,但不幸的是这一点,该计划可能会产生一个随机数'72',当用户进入它,它给了他一个暗示,而他不希望提示数,他只是想继续游戏

I though that the value of 'H' is : 72 in ASCII and I put it as the number that the user use as a hint , but unfortunately it happen that the program might generate a random number '72' and when the user enter it , it gives him a hint while he don't want the hint, he just want to continue the game

问题的:

什么正在寻找一种方法或任何把戏高级语言做这样的铸造。
我找不到到现在没有办法解决这个问题。

what am looking for is a way or any trick to do such a casting in high level language. I couldn't find till now any way to solve this problem.


有没有什么办法来清除屏幕或MIPS控制台?
因为很明显它的记忆游戏!因此,数字应消失!

AND is there any way to clear the screen or the console in MIPS? because obviously it's memorizing game! so the numbers should disappear!

任何建议或这方面的问题,是完全欢迎!

any suggestion or questions regarding this, are totally welcome!

推荐答案

所有的字符可能会被重新$ P $从键盘输入到内存时psented为ASCII,但 read_int 系统调用会尝试解析从ASCII一个整数,它会失败非数字字符。

All characters may be represented as ascii when entered from keyboard to memory, but the read_int syscall will try to parse an integer from that ascii and it will fail for non-numeric characters.

的唯一选择是使用字符串。创建一个缓冲

The only alternative is to use strings. Create a buffer

buf: .byte 0,0,0      #10-99, last byte is for null

的用户输入。读一个字符串后,检查是否在缓冲区中的第一个字符是'H'。

for the user input. After reading a string, check if the first character in the buffer is 'H'.

la $t1, buf
lb $t2, 0($t1)
li $t3, 72
beq $t2, $t3, help

如果没有'H',继续解析从字符串一个整数。

If there's no 'H', proceed to parse an integer from the string.

i = buf.length-2;
j = 1;
k = 0;
while(i >= 0) {    //go in reverse
    if(buf[i] != NULL) {
        k += (buf[i] - 48) * j
        j *= 10;
    }
    i--;
}
if(k == target)print("success");

不要忘了每次提示的时间来清除缓存。

Don't forget to clear the buffer each time you prompt.

这篇关于铸造在MIPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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