MIPS 32 обратная печать строки - PullRequest
0 голосов
/ 14 марта 2019

Выходные данные должны быть «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
...