输出应为“ LastName,FirstName” ...当我运行代码时,它将打印我姓氏的第一个字符,然后打印我的全名。 我不确定这是因为我需要另一个循环还是因为它没有读取我的完整姓氏。请帮助我了解为什么以及如何解决此问题。 预先感谢!
.data
userInput: .space 400 #Make a 4 byte (32 bit) space in memory
fName: .space 100
lName: .space 100
Prompt: .asciiz "Enter your name (FIRST LAST):\n
Output: .asciiz "Your name in reverse order is:\n
Comma: .asciiz ","
blank: .asciiz " "
.text
.globl main
main:
li $v0, 4
la $a0, Prompt #Loads address prompt from memory and stores it
syscall #Reads register $v0 for op code, sees 4 and prints the string located in $a0
li $v0, 8
la $a0, userInput #sets $a0 to point to the space allocated for writing a word
la $a1, 100 # gets the length of the space in $a1 so we cant go over the memory limit
syscall
li $v0, 4 #Loads the value 4 into register $v0 which is the op code for print string
la $a0, Output # Load address Tell Output from memory and stores it into arguments register 0
syscall #reads regsiter $v0 for op code, sees 4 and prints the string located in a$ao
la $s0, userInput
la $s1, fName #save int to $s0-$s2 registers to use throughout whole program
la $s2, lName
loop:
lb $t0, 0($s0)
lb $t1, 0($s1)
beq $t0, ' ', skipBlankSpace #else
sb $t0, 0($s1)
add $s0, $s0, 1 #increments the character array $s++
add $s1, $s1, 1
j loop
skipBlankSpace:
add $s0,$s0, 1
nextName:
lb $t1, 0($s0)
sb $t1, 0($s2)
addi $s2, $s2, 1
print: #prints the output
li $v0, 4
la $a0, lName
syscall
li $v0, 4
la $a0, Comma
syscall
li $v0 4
la $a0, blank
syscall
li $v0, 4
la $a0, fName
syscall
li $v0, 10
syscall