Solved

Backwards String

Posted on 2004-10-21
1,086 Views
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

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??
0
Question by:dabrat
    3 Comments
     
    LVL 11

    Accepted Solution

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

    Author Comment

    by:dabrat
    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
     
    LVL 11

    Expert Comment

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

    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 (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". 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