I hate asking questions like this, cause I always feel silly when I get a really simple answer, but I'm not so good with string manipulation.

Currently I'm stuck with something. I'm passing a variable to a dll, as a 'far array of far pointers'. I need to replace the characters at that address with the characters from another address.

This is what I've got so far:



;szTest db "blah, blah, blah, blah, ",0 ;exact same size as passed string
push dword ptr[szTest]
mov eax,varArgs
mov eax,[eax + 4]
pop [eax]


What is actually happening is that only the 1st 4 bytes of data at the address pointed to by eax is being overwritten instead of all of the data. All of the ptr's and dereferencing and the like is confusing me. When printing the string in question after the dll call I see "blah" and then the rest of the string instead of all of the new string data.

I'm not sure how well I explained this, but hopefully someone will be able to understand what I'm trying to do and what my problem is.


cheers,
will
Posted on 2003-05-22 10:05:13 by Will


mov ecx,lengthofstring
mov esi,source
mov edi,destination
rep movsb

or


mov esi,source
mov edi,destination
@@:
mov al,byte ptr[esi]
or al,al
jnz @F
mov byte ptr[edi],al
jmp @B
@@:

*Note: Untested and assumed that source and destination are pointers
For faster code, suggested to use mmx.
Posted on 2003-05-22 11:15:09 by roticv
Thanks roticv! You seem to be helping me a lot lately.

I was thinking there was a way to do this differently, but your advice got me headed in a different direction (byte by byte). I couldn't get your code to work. I'm sure that's because of my coding and not yours, but here's what I came up with and it seems to work just fine:



lea eax,szTest
mov edx,varArgs
mov edx,[edx + 4]
xor ecx,ecx
.while (byte ptr [eax + ecx]) != 0
mov bl,byte ptr [eax + ecx]
mov byte ptr [edx + ecx],bl
inc ecx
.endw


Thanks for steering me in the right direction,
will
Posted on 2003-05-22 12:58:03 by Will
change it to


mov esi,source
mov edi,destination
@@:
lodsb
or al,al
jnz @F
stosb
jmp @B
@@:

My mistake, I have forgot to inc edi and esi.
Posted on 2003-05-23 01:37:01 by roticv