# Program to reverse a string input by the user. Please help me out where am i going wrong? This code is giving the same output string that has been 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 # & 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++
[Moved to the Assembly forum from the Algorithms and Data Structures Forum]
Best Regards,
BioPhysEngr http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
# Program to reverse a string input by the user. Please help me out where am i going wrong? This code is giving the same output string that has been input by the user
Look at the bit I've highlighted in red. You aren't swapping the values array[start] and array[end-1] properly. You should be putting the value you saved in $t9 into $t7, not $t6:
Bookmarks