should be something minor im overlooking. im searching a string for a single character occurance then will popup a messagebox with the character.
Posted on 2002-01-10 11:51:09 by smurf
Heya smurf,

invoke lstrlen, addr String ;get length of string
mov ecx,eax ;move length into our counter
lea esi,String ;move contents of String into esi.
lodsb ;copy one byte from esi,eax
cmp al,"?" ;check al for the ?
loopne Back
mov byte ptr ,al
mov byte ptr ,0
invoke MessageBox,NULL,addr Result,0,0

I think the std is useless.. well, I never use it and it always works... Then I've never used MemCopy before.. So I dropped that one too and copied the al into manually.. There I saw that the final 0 was missing... Now it works... Hope this helps you a bit.
Edit: And I made your Result a DWORD too.
Posted on 2002-01-10 12:10:07 by JimmyClif
You can only use MemCopy to copy from one ADDRESS to another ADDRESS. If you just want to copy a value from a register to a mem location use a mov instead. You also have to NULL terminate any strings in Message boxes. Remember that if you ever fool with the direction flag, you have to restore the previous state of the direction flag when your finished. Corrected code is attached.

Smurf, I tried to respond to your PM to me but it said your inbox was full.
Posted on 2002-01-10 12:13:52 by rdaneel
Couple of things...
1) Need more space for your result, 1 char for the char in question, one for the null terminator!

2) Why use strlen?

lea edx, MyString
xor eax, eax

mov ah, BYTE PTR [edx]
inc edx
cmp ah, '?'
je @F

or ah, ah
jnz @B

; ah = '?' or 0, al = 0, and byte swapping makes it the right
; way around (thats why I chose ah not al)!
mov result, ax

; invoke MessageBox...

Posted on 2002-01-10 12:24:26 by Mirno
JimmyClif: thanks for the code works great. was wondering about the cld and std. doesnt cld start the string search from the begining of the string and moves from left to right, and std from the end of string from right to left?

also the reseaon i was using MemCopy was because i couldnt figure out why my program kept crashing while i was using eax as one of the paramaters of the invoke MessageBox. now i understand that i was missing the null character at the end.

rdaneel: im assuming that restoring the direction flag is just precausionary. i noticed that restoring the direction flag takes alot of clock cycles a total of 13 or so. im wondering how i can avoid it in my program at all costs. also feel free to resend the pm if you still have it. my pm box is now empty.

Mirno: thanks for alternative code. i really like to see different ways of coding stuff it allows me to understand it a little better. your code does contain an error though. mov result, ax holds the error.

thanks everyone for the help.:alright:
Posted on 2002-01-10 17:42:50 by smurf