Note that there are some explanatory texts on larger screens.

plurals
  1. POComplications in MIPS code of Recursive Reversal of a string
    primarykey
    data
    text
    <p>I have written this MIPS code of recursive reversal of a string. However, the output is coming out to be the same that has been input by the user. Can someone please help me out and indicate where am I going wrong? Please reply as soon as possible.</p> <pre><code># Program to reverse a string input by the user .data .align 2 array: .space 50 input: .asciiz "Enter a string: " output: .asciiz "\nThe reversed string is: " .text .globl main main: addi $s0, $zero, 50 addi $t0, $zero, 0 la $a0, input li $v0, 4 syscall la $a0, array li $v0, 8 syscall initiate: add $t0, $a0, $zero # initial address add $t1, $zero, $zero # count=0 add $t2, $zero, $zero # i=0 la $t0, array # base address of the array add $t3, $t0, $t2 # &amp; array[i] loop: lb $t3, 0($t3) # fetch array[i] beqz $t3, EndOfString # loop exits if it is a null character;array[i] !='\0' bne $t3, $0, continue # otherwise loop continues add $t1, $t1, 1 # count++ continue: add $t2, $t2, 1 # i++ j loop addi $a1, $zero, 50 jal StringReversal EndOfString: la $a0, output li $v0, 4 syscall la $a0, array li $v0, 4 syscall li $v0, 10 syscall StringReversal: add $t0, $a0, $zero # initial address add $t4, $zero, $zero # j = start = 0 addi $t5, $a1, -1 # k = end-1 SwapLoop: add $t6, $t0, $t4 lb $t7, 0($t6) # load byte array[start] add $t8, $t0, $t5 lb $t9, 0($t8) # load byte array[end-1] sb $t7, 0($t8) # array[end-1] = array[start] sb $t9, 0($t6) # array[start] = array[end-1] addi $t4, $t4, 1 # j++ addi $t5, $t5, -1 # k-- slt $t9, $t5, $t4 beqz $t9, SwapLoop jr $ra </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload