所以我只是在学习MIPS 32并且很难从用户那里获得一个整数值,然后将其打印回来。这就是我所拥有的:
.text
main:
la $a0, str1 #put the address of the string to display in register $a0
li $v0, 4 #move 4 to the register $v0. This is the system service to display string messages
syscall #system call to output str1
li $v0, 5 #load system service to read integer
syscall #Integer inputted is saved to register $v0
sw $v0, x #store contents of $t0 into x, x = $t0
la $a0, x #put the address of x to display in $a0
li $v0, 4 #4 = system service to display strings
syscall #system call to output x
.data
x: .word 0
y: .word 0
z: .word 0
str1: .asciiz "Please enter the value for X:";
str2: .asciiz "Please enter the value for Y:";
str3: .asciiz "Please enter the value for Z:";
输入1将'r'打印到控制台窗口。
答案 0 :(得分:1)
假设我们正在谈论MARS,则调用5将在$v0
中返回一个整数,而调用4将打印以NULL结尾的ASCII字符串。整数不是以NULL结尾的ASCII字符串。
您可能希望通过调用服务1和x
的calue而不是其地址来替换最终调用。所以:
lw $a0, x #put the address of x to display in $a0
li $v0, 1 #1 = system service to display an integer
syscall #system call to output x