this works well parsing from the beggining. it works from left to right moving each character into buffer until it reaches a period then invokes a message box.

i need for it to start at the end of the string and work its way from right to left until it reaches a period. i need everthing before the period to be in the buffer and everything after stripped off. the string doesnt need moved into buffer if it doesnt have to be.

.586

.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib user32.lib
includelib kernel32.lib
includelib \masm32\lib\masm32.lib

.data
testing db "what i.s the meaning of life",0

.data?
buffer dd ?

.code
start:
lea esi,testing
lea edi, buffer
@@:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi
cmp al, "."
jne @B
mov byte ptr [edi-1], 0

invoke MessageBox,0,addr buffer,0,0
invoke ExitProcess,NULL
end start
Posted on 2002-01-29 16:59:00 by smurf
There's an opcode that allows you to do string manipulations backwards:

std

This sets the direction flag so that scas, movs, and stos, work backwards.

Make edi point to the end of the string by scanning for the trailing zero at the end. then use "std" and scan it for the period. manipulate ecx to get the length of the string up to the period and set edi to the beginning of the string. Use "cld" to cleat the direction flag and do a movsb.

You must remember to use cld, otherwise APIs will mess up and you won't have a clue what the problem is.
Posted on 2002-01-29 17:49:58 by Hel
Hi smurf!

I just modified your code... can't test it here, because I'm at work :)



.586
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib user32.lib
includelib kernel32.lib
includelib \masm32\lib\masm32.lib

.data
testing db "what i.s the meaning of life",0

.data?
buffer db 512 dup (?)

.code
start:
invoke lstrlen, addr testing
lea esi, testing
lea edi, buffer
add esi, eax
@@:
mov al, byte ptr [esi]
mov byte ptr [edi], al
dec esi
inc edi
cmp al, "."
jne @B
mov byte ptr [edi-1], 0

invoke MessageBox,0,addr buffer,0,0
invoke ExitProcess,NULL
end start


Edit: Overlooked the "buffer dd ?" and changed it.

Edit 2: Can someone please test it? Think it just reverses the string (maybe I'm to confused from that VBA programming here at work :( )
Posted on 2002-01-30 01:11:33 by bazik
smurf,

You still need to be careful to allocate the bytes
needed for "buffer". In your code it is only dd
but needs to be at least as big as your largest
possible "testing" string!

farrier
Posted on 2002-01-30 02:02:18 by farrier
bazik you code comes up with an empty messagebox. i also noticed that when you get the string length you didnt move eax into ecx. i changed that too and still it didnt work. also to start from the end of the string and move backwards shouldnt there be an std in there somewhere?

thanks for the help guys!
Posted on 2002-01-30 10:39:43 by smurf


push esi

mov esi, source
mov ecx, dest
mov edx, ecx

@@:
mov al, [esi]
mov [ecx], al

cmp al, "."
cmove ecx, edx
; If you find a dot, start from the left most
; position of the buffer again!

inc esi
inc ecx

or al, al
jnz @B


You still need to scan from left to right (unless you don't mind filling your buffer from right to left, then return the start address of the string within that buffer, or an offset within the buffer etc.), because you want the left most character in the left most position, which is impossible to determine without scanning the whole string...
If you are going to scan the whole string, you may as well do some real work then as well!

It need a .686 processor to use the cmov instruction, you could always use a jne instead, but why not use all that complex jiggery pokery Intel kindly provided us with :)

Mirno
Posted on 2002-01-30 11:42:19 by Mirno
thanks everyone. Mirno very interesting info ive never seen the cmov in action before.
Posted on 2002-01-30 21:51:47 by smurf
What is a cMove
Posted on 2002-01-30 22:00:34 by cmax
The CMOV instructions were introduced in the 686 (PPro/PII processor group), and are conditional move instructions.

They follow pretty much the same naming convention as the conditional jumps (J** - CMOV**).
cmovE - move if empty/zero flag is set.

The reason they are so good is because they don't rely on branch prediction, this means they cannot cause the processor to stall by mis-predicting. It is also very simple to use in places (ie this one) and will replace several instructions (usually one of which is a jump).

Mirno
Posted on 2002-01-31 02:57:13 by Mirno
I got the stuff you showed me how to to Down Packed....Create Files, End of string and other related stuff....You must have been on vacation...Welcome Back....
Thanks
Posted on 2002-01-31 03:44:49 by cmax