im able to do some scans backwards but havent been able to do any moves. anyone got a small example i can take a look at?
Posted on 2002-02-03 11:09:24 by smurf
Can you explain your problem a little more? maybe with a text example? Not sure what you mean "from left to right".

Sliver
Posted on 2002-02-03 11:11:25 by Sliver
Well I'm not sure what you mean but if you have a string and you want to move it somewhere else in memory then you'd do this

mov esi, offset MyString

mov edi, offset MyEmptyStringBuffer
mov ecx, 100 ;that would be if your string was 100 bytes long
rep movsb
Posted on 2002-02-03 11:19:28 by Quantum
I have a routine here that you can specify how many spaces you can move from left to right(not what you wanted :grin: ).

invoke MoveStr, OFFSET mystringdata, OFFSET buffer, 10

First Parameter: source string
Second Prameter: destination string(buffer)
Third Prameter: number of spaces

if you specify 10 you'll see 10 x's( x means spaces - just to let you see it's working).

If you want actual spaces change x to 20h.



.386
.MODEL flat, stdcall
option casemap:none

INCLUDE \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\kernel32.lib
INCLUDE \masm32\include\user32.inc
INCLUDELIB \masm32\lib\user32.lib

.data

mystringdata db "hello cruel world", 0
buffer db 50 DUP(0)

.code

MoveStr PROC USES esi edi lpszStrInp:DWORD, lpszStrBfr:DWORD, nMove:DWORD

mov esi, lpszStrInp
mov edi, lpszStrBfr
mov eax, nMove

@@:
or eax, eax
je @f
mov BYTE ptr [edi], "x"
inc edi
dec eax
jmp @b

@@:

mov dl, BYTE ptr [esi]
mov BYTE ptr [edi], dl
or dl, dl
je @f
inc esi
inc edi
jmp @b

@@:

ret

MoveStr ENDP

Start:

invoke MoveStr, OFFSET mystringdata, OFFSET buffer, 10
invoke MessageBox, 0, OFFSET buffer, 0, 0
invoke ExitProcess, 0

END Start


I'm not sure if this is the "kind" of logic you want for your program.
Posted on 2002-02-03 13:44:29 by stryker
Hello smurf,
I made a function sometime ago to replace substrings in a string.
Inside the routine, I have to move the rest of the string depending if the new substring is larger than the old substring.
It moves from left to right and from right ro left.
Maybe it helps you.
Here it is:


ReplaceString proc SourceString:DWORD, SubString:DWORD, NewSubString:DWORD
LOCAL NewLenSourceString:DWORD
LOCAL LenSourceString:DWORD
LOCAL LenSubString:DWORD
LOCAL LenNewSubString:DWORD
LOCAL esi1:DWORD
LOCAL movecount:DWORD
LOCAL movemode:DWORD

pushad

mov esi, SourceString
mov edi, SourceString
mov ebx, SubString
mov edx, NewSubString

invoke lstrlen, SourceString
mov LenSourceString, eax
invoke lstrlen, SubString
mov LenSubString, eax
invoke lstrlen, NewSubString
mov LenNewSubString, eax
.IF eax>LenSubString
mov movemode, 1
.ELSE
mov movemode, 0
.ENDIF

compare1:
mov ah, [ebx]
compare1loop:
mov al, [esi]
inc esi
cmp al, 0
je theend
cmp al, ah
je compare2
jmp compare1loop

compare2:
dec esi
mov esi1, esi
compare2loop:
mov al, [esi]
inc esi
mov ah, [ebx]
inc ebx
cmp ah, 0
je found
cmp al, ah
jne backtocompare1
jmp compare2loop

backtocompare1:
mov ebx, SubString
mov esi, esi1
inc esi
jmp compare1

found:
cmp movemode, 1
je found1
mov esi, esi1
copyloop0:
mov al, [edx]
inc edx
cmp al, 0
je copydone0
mov [esi], al
inc esi
jmp copyloop0
copydone0:
xor eax, eax
xor ecx, ecx
mov ecx, LenSubString
sub ecx, LenNewSubString
mov eax, LenSourceString
sub eax, ecx
mov NewLenSourceString, eax
mov edi, esi
mov esi1, esi
add esi, ecx
moveloop0:
mov al, [esi]
inc esi
mov [edi], al
inc edi
cmp al, 0
je backtocompare3
jmp moveloop0

found1:
xor eax, eax
xor ecx, ecx
mov ecx, LenSubString
sub ecx, LenNewSubString
mov eax, LenSourceString
sub eax, ecx
mov NewLenSourceString, eax
mov esi, SourceString
add esi, LenSourceString
add edi, NewLenSourceString
xor eax, eax
xor ecx, ecx
mov eax, esi1
add eax, LenSubString
mov ecx, esi
sub ecx, eax
add ecx, 1
mov movecount, 0
moveloop:
mov al, [esi]
dec esi
mov [edi], al
dec edi
inc movecount
cmp ecx, movecount
je copynewsubstr
jmp moveloop

copynewsubstr:
mov esi, esi1
copyloop:
mov al, [edx]
inc edx
cmp al, 0
je backtocompare2
mov [esi], al
inc esi
jmp copyloop

backtocompare3:
mov esi, esi1
backtocompare2:
mov edi, SourceString
mov ebx, SubString
mov edx, NewSubString
mov eax, NewLenSourceString
mov LenSourceString, eax
jmp compare1

theend:
popad
ret
ReplaceString endp
Posted on 2002-02-03 18:10:04 by dilau
oops okies here it goes. i need to move one character at a time starting from the end of a string into a buffer until ive moved the whole string contents into the buffer.
Posted on 2002-02-03 19:44:50 by smurf
Posted on 2002-02-03 19:59:37 by stryker