I had been writing a program that enforces the loop instruction with indirect addressing but I need it to copy a string from source to target, reversing the character order in the process. I need to use the variables:

source BYTE "This is the source string",0
target BYTE SIZEOF source DUP('#')

After that I need to insert the following statements right after the loop to display the hexadecimal contents of the target string:

mov esi, OFFSET target                     : offset of variable
mov ebx, 1                                      : byte format
mov exc, SIZEOF target                    : counter
call DumpMem

so far this is all I have and what I've been following by to help me and I'm pretty sure there is some unnecessary garbage in there...

INCLUDE Irvine32.inc
.data
val1  WORD 1000h
val2  WORD 2000h

arrayB BYTE  10h,20h,30h,40h,50h
arrayW WORD  100h,200h,300h
arrayD DWORD 10000h,20000h

.code
main PROC


;  in-Direct Addressing (byte array):
	mov eax,offset arrayB
	mov ecx, LENGTHOF arrayB ; This would give us "5"
	mov bl,0
	
  L1:add bl, [eax]
	inc eax
	loop L1
	
;  Direct-Offset Addressing (word array):
;	mov ax,arrayW		; AX = 100h
;	mov ax,[arrayW+2]	; AX = 200h

;  Direct-Offset Addressing (doubleword array):
;	mov eax,arrayD				; EAX = 10000h
;	mov eax,[arrayD+4]			; EAX = 20000h
;	mov eax,[arrayD+TYPE arrayD]	; EAX = 20000h

	exit
main ENDP
END main

So if someone knows any helpful tips or something that'd be great cuz i'm pretty stuck with this.

include /masm32/include/masm32rt.inc 
.data
  source db "this is the source",0
.data 
  target db 255 dup(?)
.code
start:
  mov ecx,sizeof source-1
  mov edi,offset target
@@:
  mov al, byte ptr [source+ecx-1]
  stosb
  loop @b
mov byte ptr[edi],0
print addr target,13,10
exit
end start

code for masm32, think u get the idea...

greetz,
kermit

Hey thanks a lot for helping me so quick. Unfortunately, i'm not that great at Assembly Language so I don't exactly follow where you are going with this coding. I tried to run it but I got an error on the line where its supposed to print out the output.

hm, do u get an compile error or does it crash when u run the exe ?
remember to compile with masm console assemble& link: (.bat file)

@echo off
 if exist %1.obj del %1.obj
 if exist %1.exe del %1.exe
 \masm32\bin\ml  /coff /c %1.asm
 if errorlevel 1   goto errasm
 \masm32\bin\Link /SUBSYSTEM:console    %1.obj
 dir %1.*
 :errasm

i get the error

Error 1 error A2008: syntax error : print c:\Irvine\examples\ch04\Project_sample\main.asm

and the error
Error 2 error PRJ0019: A tool returned an error code from "Assembling..." Project

when it's compiling. Sorry again but i'm a bit nooby at this so i don't understand the jargain you used above. But thanks again for getting back so soon. It's much appreciated.

my code works with standard masm32 installation, i'don't use the irvine.inc file, instead
include /masm32/include/masm32rt.inc contains all the needed "macros/apis/include" commands.
u can just skip the print macro and replace it with the code u whished to use

mov esi, OFFSET target                     : offset of variable
mov ebx, 1                                      : byte format
mov exc, SIZEOF target                    : counter
call DumpMem

( try: mov ecx,sizeof source :-)
- or use the standard api command

invoke StdOut,addr target

if u have included the required api files..

I had this same assignment. Here's how I solved it using indexed addressing:

INCLUDE Irvine32.inc

.data
source  BYTE  "This is the source string",0
target  BYTE  SIZEOF source DUP('#')

.code
reversecopy PROC

	mov  ESI,0                     ; source register
	mov  EDI,SIZEOF source-2D      ; destination register
	mov  ECX,SIZEOF source         ; loop counter

Copy:
	mov  DL,source[ESI]		; get a character from source
	mov  target[EDI],DL		; store it in the target
	inc  ESI		        ; move to next character - increment the source index
	dec  EDI                ; decrement the destination index
	loop Copy		        ; repeat for entire string
	
;
; Outputresults
;
	mov ESI,OFFSET target     ;offset of variable
	mov EBX,1                 ;byte format
	mov ECX,SIZEOF target     ;counter
	call DumpMem
	
;
; Our results should be: 67 6E 69 72 74 73 20 65 63 72 75 6F 73 20 65 68
; 74 20 73 69 20 73 69 68 54
;
;Return to operating system
;
;	exit

reversecopy ENDP
END reversecopy
This question has already been answered. Start a new discussion instead.