[英]how to repeat a mips program using user input 'y'?
我有这个程序,用户输入 integer,程序只是简单地打印它。 该程序的另一个 function 是它应该询问用户是否要重复该程序并输入另一个数字。
因此,如果用户想继续,则应输入“y”,否则应输入“n”。
.data
repeat: .asciiz "\n Repeat [y/n]? "
store: .byte ' '
.text
.globl main
main: # Main function
li $v0, 5
syscall
move $a0, $v0
li $v0, 1
syscall
li $v0, 4
la $a0, repeat
syscall
li $v0, 12
syscall
la $s0, store
sb $v0, store
syscall
beq $v0, 'y', main
beq $v0, 'Y', main
li $v0, 10
syscall
使用此源代码,程序可以读取并打印我输入的 integer,
但是这里的问题是,每当我输入'y'或'n'并回车时,程序都会提示有错误。
问题出在beq说明上吗? 还是在它读取字符的部分?
我只是 MIPS 编程的新手,但仍有一些部分让我感到困惑。
谁能指出我哪里做错了?
.data
str1: .asciiz "\nEnter an integer value: "
str2: .asciiz "You entered: "
repeat: .asciiz "\nRepeat [y/n]? "
store: .byte ' ' # This will hold a single byte
.text
.globl main
main: # Main function
la $a0, str1 # Load address of 'str1' to $a0
li $v0, 4 # Print 'str1' string
syscall
li $v0, 5 # Reads the integer input
syscall
move $s0, $v0 # Moves the value of $v0 to $s0
la $a0, str2 # Load address of 'str2' to $a0
li $v0, 4 # Prints the 'str2' string
syscall
move $a0, $s0 # Copy the integer value
li $v0, 1 # Prints the integer input
syscall
la $a0, repeat # Load address of repeat to $a0
li $v0, 4 # Print 'repeat' string
syscall
li $v0, 12 # Reads the char input
syscall
la $s0, store # Load address of 'store' to $s0
sb $v0, store # Store byte
beq $v0, 'y', main # If user input is 'y', then program is branched to the 'main' function
li $v0, 10
syscall # System call to exit program
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.