?
Solved

Backwards String

Posted on 2004-10-21
3
Medium Priority
?
1,120 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
Comment
Question by:dabrat
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
dimitry earned 150 total points
ID: 12377269
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
ID: 12414728
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
ID: 12414766
You need to do:
mov ecx, (SIZEOF target) - 1
  and you need to
mov target[esi], 0
  at the end
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
Before you approach an Ionic Mobile App development company for developing mobile apps using the ionic framework, you must know why you should choose the framework. Let's try to understand that through this article.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

616 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