简体   繁体   中英

MIPS reversing string with Add a space

How to Add a space between every two characters of the input word and then print it out.

In my program it can reversing a String

Loop:

        sub     $t2, $t2, 1     #this statement is now before the 'load address'
        la      $t0, buffer($t2)   #loading value
        lb      $a0, ($t0)
        syscall


        bnez    $t2, Loop       

        li      $v0, 10              #program done: terminating
        syscall
        jr $ra

My Result

Enter string: Hello

Original: Hello

Reversed: olleH

but How to Add a space between every two characters of the input word

Enter string: Hello

Original: H ello

Reversed: olle H

The code you provided is printing a reversed string stored in buffer, but the reversed string is not stored back. If that was your intent, then all you need is to print a space after each character printed.

That is accomplished by adding these two lines after the syscall that prints each character (before the bnez $t2, Loop )

  li $a0, ' '
  syscall

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM