Backwards String

I am trying to take a string from one variable and stick it into another variable backwards.  YES this is a school project, but I am stuck.  Here is my code.



; this program copies a string from one variale to another and displays the string backwards

INCLUDE Irvine32.inc

.data

source BYTE "This is the source string", 0                ; orig string
target BYTE SIZEOF source DUP(0)                          ; backwards string

.code
main PROC
   
  mov edx, OFFSET source
  call WriteString
  call Crlf
 
  mov ecx, SIZEOF target
  mov esi, 0
 
L1:
  movzx eax, source [esi]
  push eax
  inc esi
  LOOP L1
 
  mov ecx, SIZEOF target
  mov esi,0
 
L2:
  pop eax
  mov source[esi], al
  inc esi
  LOOP L2
 
  mov edx, OFFSET target
  call WriteString
  call Crlf
 
  mov esi, OFFSET target
  mov ebx, 1
  mov ecx, SIZEOF target-1
  call DumpMem
exit      
main ENDP
END main

when I run the program there is nothing in my target variable.  Can anyone help me??
LVL 1
dabratAsked:
Who is Participating?
 
dimitryCommented:
You can try:
L2:
  pop eax
  mov target[esi], al  ; <-- it seems like you made copy/paste too quickly
  inc esi
  LOOP L2
0
 
dabratAuthor Commented:
I tried your code snippet that you suggested, it works but the first letter is null and it drops off the last letter completly.

Thanks for your help
0
 
dimitryCommented:
You need to do:
mov ecx, (SIZEOF target) - 1
  and you need to
mov target[esi], 0
  at the end
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.