ok i allocated some memory and stored some info in it. then set a pointer to the fist byte of memorynow set as pMemory. i need to check the first 3 bytes of the memory for a string such as '200'. the code saple below the came with rdaneel's newsreader sample works but i really dont understand it.



cld ;clear direction flag, process string left to right
mov eax, 0 ;set eax to zero
mov esi, pMemory ;move pointer set to 0 into esi
lodsb ;confused at the rest.. need some baby step explantions
shl eax, 8
lodsb
shl eax, 8
lodsb


the first 3 bytes i need are stored in eax. this works well and was wonerding if this is the best approach to use?
Posted on 2002-01-06 11:08:30 by smurf
How about this?


mov ecx, pMemory ;move pointer in some register
mov eax, [ecx] ;get first dword
and eax, 00ffffffh
.IF eax==00303032h
; it's 200
.ENDIF


Say you would have the string "200X" as the first 4 bytes of the memory block. When you read this dword, it will be read as a value in little endian format so eax becomes "X002". Mask out the "X" you don't need by anding with 00FFFFFFh. you will have "?002" in eax then (where ? stands for NULL). Then you can compare it with a fixed value like the string "200", just remember you have to swap the bytes ("200" is 32h, 30h, 30h --> compare with 303032h).

Thomas

edit:fixed value in code
Posted on 2002-01-06 11:20:47 by Thomas
I forgot about rdaneel's code:


cld ;clear direction flag, process string left to right
mov eax, 0 ;set eax to zero
; eax = "????", ? stands for NULL byte
mov esi, pMemory ;move pointer set to 0 into esi
lodsb
;lodsb loads one byte at [esi] into al, so:
; eax = "???A", where A is the first character in memory block
shl eax, 8
; eax = "??A?", shift 8 bits left
lodsb
; load another byte in al:
; eax = "??AB"
shl eax, 8
;shift:
; eax = "?AB?"
lodsb
; load third byte in al:
; eax = "?ABC"


Thomas
Posted on 2002-01-06 11:24:47 by Thomas
lodsb moves a byte from the address pointed to by esi into eax.

Example:
----------------------------------------------------------------------------------
Variable db "Hello World!",0


lea esi, Variable
lodsb ;This would move "H" into al register and increment esi by 1.
shl eax, 8 ;Now we shift the eax reg 8 bits to the left
lodsb ;This now moves "e" into the al register.
shl eax, 8
lodsb ;Moves "l" into al
shl eax, 8
lodsb ;Moves "l" into al

----------------------------------------------------------------------------------

Now eax register contains the word "Hell" in this fashion:
High word = He
Low word = ll

I hope I didn't insult your intelligence but I was trying to be as thorough as possible in my explanation. This is probably not the easiest way to check but I couldn't think of a quicker one.
Posted on 2002-01-06 11:30:00 by rdaneel
thank you thomas for the different route i can take.

thank you rdaneel that really clears it all up for me. as for insulting me, you were far from it. i needed baby steps and really glad you help me out.
Posted on 2002-01-06 11:43:45 by smurf