编写程序,以便程序打印与用户输入的标识号相对应的用户名。
我有我需要的所有陈述。我不确定如何实现循环来检查用户输入的ID数组是否正确。
@Named
用户输入是否有效的输出:
.data
id: .word 1523, 6540, 2213, 156, 956
names: .asciiz "john", "mary", "rudolph", "anthony", "jerry"
enterID: .asciiz "Please enter an id:\n"
foundL .asciiz "Name is: "
invalid: .asciiz "Not found!\n"
.globl main
main:
# Print enterID
li v0, 4
la a0, enterID
syscall
# Get user input
li v0, 5
syscall
sw a0, t0
# Display name
jal idCheck
# Exit program
li v0, 10
syscall
idCheck:
# check if user input is valid
noMatch:
# Print incalid
li v0, 4
la a0, invalid
syscall
# Print enterID
li v0, 4
la a0, enterID
syscall
# Get user input
li v0, 5
syscall
sw a0, t0
j idCheck
display:
jr ra
如果用户输入无效,则输出:
Please enter an id:
956 <---- this is the input
Name is: jerry