我无法理解为什么在第 20 行出现语法错误,sw $v0, $t0
. $v0
应该是从上一次调用 read int 返回的整数,并且$t0
是一个临时寄存器。谢谢!
.data
msg: .asciiz "Hello world.\n"
promptint: .asciiz "Type an int: "
promptstring: .asciiz "Type a string: "
.text
main:
li $v0, 4 #print "Hello world."
la $a0, msg
syscall
la $a0, promptint #prompt for int
syscall
li $v0, 5 #read int
syscall
sw $v0, $t0
li $v0, 1 #print int
la $a0, $t0
syscall
li $v0, 4
la $a0, promptstring #prompt for string
syscall
li $v0, 8 #read string and length of string buffer
syscall
sw $a0, $t1 #string
sw $a1, $t2 #length
li $v0, 4 #print string
la $a0, $t1
syscall
li $v0, 1
la $a0, $t2 #print length
syscall
j done
done:
li $v0, 10
syscall