ive been using lodsb then stosb so that i can do a cmp with the contents of al to know when to stop my loop.
@@:

lodsb
stosb
cmp al,20h
jne @B:


its probably possible to use movsb instead. ive been messing around with movsb but i havent been able to get it to work. im hoping for a little mini example of how i can use movsb and make it stop when i want it to. i do realize that movsb uses ecx as a counter and decreases it but i have an undetermined amount of bytes to move.

please dont tell me to use scan to determined the amount of bytes i need moved by pinpointing the location and moving the amount into ecx otherwise i will have to keel you.:grin:
Posted on 2002-02-05 22:07:01 by smurf
movsb by itself does no ecx messing. It copies byte from
to , and increases both esi and edi. That's all it does. When
you use the rep prefix, it starts using ecx. The "rep movsb" (and
even better, movsd) is great when you know the length beforehand.
You can't break a "rep movs" sequence based on data.

If your code snippet doesn't require high speed, your current code
will work fine, and has the advantage of being quite small. Unless
you'll be processing massive amounts of data this way, I would focus
on optimizing / implementing other parts of the application.
Posted on 2002-02-05 22:18:27 by f0dder
It is better to use MOV instruction in your above case.
@@:

mov al,[esi]
inc esi
mov [edi],al
inc edi
cmp al,20h
jne @B
Less code is not always a better thing. If you are just copying space separated words from a string, then it might be better to put zero bytes where the spaces are and just store pointers to the positions within the string - instead of copying the sub-strings.
.data?

MyTokens dd MAXTOKENS dup(?)
TokenCount dd ?

.code
invoke GetTokenPointers, ADDR InputString, ADDR MyTokens
mov TokenCount, eax
...
mov edx, OFFSET MyTokens
mov eax, TokenCount
@@:
; [edx] is pointer to token
; do something with it...

add edx,4
dec eax
jne @B
...

GetTokenPointers PROC theString:DWORD, tokBuffer:DWORD
mov edx, theString
mov ecx, tokBuffer
push edx
dec edx
xor eax,eax ; number of tokens
@@:inc edx
cmp BYTE PTR [edx],20h
je aSpace
cmp BYTE PTR [edx],0
jne @B
pop DWORD PTR [ecx + eax*4] ; store last one
inc eax
ret
aSpace:
mov BYTE PTR [edx],0 ; clear byte
pop DWORD PTR [ecx + eax*4] ; store pointer to sub-string
inc eax
push edx
jmp @B
GetTokenPointers ENDP
Warning: Code untested and subject to spurious modifications. :rolleyes:
Posted on 2002-02-05 22:21:47 by bitRAKE
fodder: oops ya i was thinking about the rep prefix before the movsb.

bitrake: very good point on that less code isnt always better. you just woke me up there thx.

i have another question. i need to reuse some code in a procedure i made. here is a snipet of the code i need to reuse:
AddDir:         

pushad
mov item.iItem,0
mov item.iSubItem,0
mov item.imask,LVIF_TEXT + LVIF_IMAGE
push xName
pop item.pszText
mov item.cchTextMax,sizeof xName
mov item.iImage,0
invoke SendMessage,hListView,LVM_INSERTITEM,0,addr item
popad
ret


i need to call this from my procedure(this is actually in my procedure but below my routine) and have a paramater to replace the xName in my call.

call AddDir, xNamesReplacement <-- so how do i pass this paramate to replace xName?
Posted on 2002-02-05 22:41:49 by smurf
YourAddDir PROC xName:DWORD

; pushad ; are these really needed?
mov item.iItem,0
mov item.iSubItem,0
mov item.imask,LVIF_TEXT + LVIF_IMAGE
push xName
pop item.pszText

invoke YourStringLength,xName
mov item.cchTextMax,eax ; sizeof xName

mov item.iImage,0
invoke SendMessage,hListView,LVM_INSERTITEM,0,addr item
; popad
ret
YourAddDir ENDP
That's it! :grin:
Edit: Woops a PROC won't work here if item is a LOCAL. :stupid:
Posted on 2002-02-05 22:48:31 by bitRAKE
the pushad and popad had i used just for debugging purposes. my code was crashing and at the time i didnt know which registers were the trouble makers so i just saved them all. thanks for the help and the token code.:)
Posted on 2002-02-05 23:50:21 by smurf
You might not have seen the token code before - I usually don't like opening my mouth too big without providing an example of some sort. ;) It just so happened that the code I came up with didn't work at all, so I clipped it and played with it some more until I felt it was working. Granted I've never assembled the code above - I just think it'll work. :grin: Mainly, I just was hoping to convey the idea of not moving the data, but transforming it into a usable form.
Posted on 2002-02-06 00:00:20 by bitRAKE