ユーザーからの入力として整数を受け取るプログラムがあります(syscall 5を使用)。ユーザーが特殊文字を入力したとき! @ # $ % ^ _ - ) (クラッシュする整数の代わりに、クラッシュする代わりにエラーメッセージを表示するようにプログラムを修正するにはどうすればよいですか?
これは私が書いたコードです
la $a0, prompt # prompt the message ask for the answer n
li $v0, 4
syscall
li $v0, 5 # input the answer
syscall
add $t1, $zero, $v0
# store the answer in $t1
blt $t1, $s0, negative # check for number entered < $s0
bgt $t1, $s1, exceed # check for > $s1 number
la $a0, blank # blank line
li $v0, 4
syscall
サンプル出力:
This is a number guessing game between 0- 100. Let's begin.
Chances remains: 6
Enter your guess: 56
The secret number is higher than : 56
Chances remains: 5
Enter your guess: 67
The secret number is higher than : 67
Chances remains: 4
Enter your guess: 75
The secret number is lower than : 75
Chances remains: 3
Enter your guess: 74
The secret number is lower than : 74
Chances remains: 2
Enter your guess: 72
The secret number is lower than : 72
Chances remains: 1
Enter your guess: 70
The secret number is lower than : 70
Chances remains: 0
Sorry...You lost.
The secret number is: 69
Do you want to play again?
1.Yes
2.No
Choice: 2
Your average guess: 3
-- program is finished running --