用户输入问题
我这周刚刚开始用汇编语言编程,但遇到了一些麻烦。我正在使用 PCSpim 在 MIPS 中编写一个程序,该程序提示用户输入两个非负整数。但出于某种原因,我的代码使两个提示出现在同一行,并且只接受一个整数。有人可以帮我吗?我根本不习惯语法,可以使用一些指针。
.text
.align 2
.globl main
# Prompts the user for two non-negative integers, x and y, and then finds the greatest common divisor of the two.
main:
la $a0, prompt
li $v0, 4
syscall # Display prompt for the x integer.
li $v0, 5
syscall # Get x integer response.
move $t0, $v0
la $a1, secondprompt
li $v1, 4
syscall # Display prompt for the y integer
li $v1, 5 # Get y integer response
syscall
move $t1, $v1
prompt: .asciiz "Enter a non-negative integer: \n"
secondprompt: .asciiz "Enter a second non-negative integer: \n"
I've literally just started programming in assembly language this week and I'm having some trouble. I'm making a program in MIPS using PCSpim and the program prompts the user to enter two non-negative integers. For some reason though, my code makes both prompts appear on the same line and will only accept one integer. Can anyone help me out? I'm not used to the syntax at all and could use a few pointers.
.text
.align 2
.globl main
# Prompts the user for two non-negative integers, x and y, and then finds the greatest common divisor of the two.
main:
la $a0, prompt
li $v0, 4
syscall # Display prompt for the x integer.
li $v0, 5
syscall # Get x integer response.
move $t0, $v0
la $a1, secondprompt
li $v1, 4
syscall # Display prompt for the y integer
li $v1, 5 # Get y integer response
syscall
move $t1, $v1
prompt: .asciiz "Enter a non-negative integer: \n"
secondprompt: .asciiz "Enter a second non-negative integer: \n"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里读到应该使用 $a1 和 $v1 ?两个数字都应该是 $a0 和 $v0。
Where have you read that you should use $a1 and $v1? It should be $a0 and $v0 for both numbers.