Backwards String

Posted on 2004-10-21
Last Modified: 2008-03-03
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



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

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

when I run the program there is nothing in my target variable.  Can anyone help me??
Question by:dabrat
    LVL 11

    Accepted Solution

    You can try:
      pop eax
      mov target[esi], al  ; <-- it seems like you made copy/paste too quickly
      inc esi
      LOOP L2
    LVL 1

    Author Comment

    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
    LVL 11

    Expert Comment

    You need to do:
    mov ecx, (SIZEOF target) - 1
      and you need to
    mov target[esi], 0
      at the end

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    Suggested Solutions

    Read about why website design really matters in today's demanding market.
    Know what services you can and cannot, should and should not combine on your server.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now