我正在尝试从用户读取最多100个字符的输入,然后反转输入。当检测到Z并且应该能够读取多行时,我的程序应该停止读取。现在我可以通过一行读取输入并且它可以工作,我只是在与多线部分挣扎。以下是我到目前为止的情况:
.data
buffer: .space 100
str2: .asciiz "\nYou wrote:\n"
str1: .ascii "Enter string (max 100 chars): "
.text
main:
la $a0,str1 #Load and print string asking for string
li $v0,4
syscall
li $v0, 8 #take in input
la $a0, buffer #load byte space into address
li $a1, 100 # allot the byte space for string
move $t1, $a0 #save string to t1
syscall
la $a0, str2 #load and print “You wrote" string
li $v0,4
syscall
la $a0, buffer #reload byte space to primary address
li $t2, 0
strLen: #getting length of string
lb $t0, buffer($t2) #loading value
add $t2, $t2, 1
bne $t0, $zero, strLen
sub $t2, $t2, 1
li $v0, 11 #load immedialtey - print low-level byte
Loop:
la $t0, buffer($t2) #loading value
lb $a0, ($t0)
syscall
sub $t2, $t2, 1
bnez $t2, Loop
li $v0,10 #end program
syscall