我正在研究一个类项目,我要做的是,当消息提示“请输入一个整数:”并且alsoto输入一个字符时,请求用户输入2个整数,并输入一个字符“请输入一个运算符(+ , *, -, /)“ 弹出。有人可以看看这段代码并告诉我我做错了什么?第一条指令打印但我得到一个带有字符输入的错误消息。
真的很感激
.data
prompt: .asciiz "Please enter an integer\n"
message: .asciiz "Please enter an operator (+, - , * , / ):"
usercharacter: .space 2
.text
.globl main
main:
li $v0, 4 #system call code for printing a string is 4
la $a0, prompt #adress of string is argument 0, to print string
syscall # telling the system to execute the action
li $v0, 5 # system call for reading and displaying input
syscall
move $t1, $v0 # store input one into register $a1
li $a0, message
li $v0, 4
syscall
la $a0,usercharacter
li $a1, 2 #allocating a space for 2 caracters
li $v0 12
syscall
li $v0, 4 #system call code for printing a string is 4
la $a0, prompt #adress of string is argument 0, to print string
syscall # telling the system to execute the action
li $v0, 5 # system call for reading and displaying input
syscall
move $t2,$v0 #print the prompt message for the user to input
li,$v0,10
syscall
答案 0 :(得分:0)
我希望这有帮助,
问题输入1个整数和一个运算符(+, - ,*,/)然后是第二个整数。这是代码。
.data
input1: .asciiz "Please enter an integer: "
input2: .asciiz "Please enter an operator(+, -, *, /): "
input3: .asciiz "Enter second value: "
newline: .asciiz "\n"
.text
.globl main
main:
li $v0, 4
la $a0, input1
syscall #printing input 1
li $v0, 5
syscall
#reading and storing first value
move $t1, $v0
li $v0, 4
la $a0, input2
syscall #printing input 2
li $v0, 12
syscall #reading operator
move $t9, $v0 #storing operator
li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, input3
syscall #printing input 3
li $v0, 5
syscall
#reading and storing second value
exit:
li $v0, 10
syscall # ending main
谢谢