Hi all,
After getting the textline from the text box and I want to split the words in that textline which separated by space character
I think of using INSTR macro to get the 1st position of the first space and SUBSTR macro to take the 1st word out but I dont know how to use those two macro to retrieve the return value !!! so could any one of you post some lines show me how to use those two macro
or any other solution about this are welcome
Any reply from you are helpful
minh
Posted on 2003-08-18 03:36:11 by nvm
Since I like study asm by method of try&errors, I'm not familiar with these macros ;)

Why not use simple SCASB or somthing like below instead?

mov EDI, pString
@@: cmp byte ptr ,0 ; null-terminated string?
jz @end_of_string
inc EDI ;next byte
cmp byte ptr ," "
jne @b
; here EDI=space address+1 = next word
; use EDI
jmp @b
@end_of_string:

I'll be pleased if this will work:tongue:
Posted on 2003-08-18 04:15:19 by S.T.A.S.
	mov edi, pString

jmp Next_Word

_1: cmp [edi], " "
lea edi, [edi+1]
; mostly taken; predicted [b]not[/b] taken :(
jne _3

; ###################################
; do something with string ESI to EDI - 1
; (save EDI if modified)
; ###################################

Next_Word:
; save start of string
mov esi, edi

_3 cmp [edi], 0
; taken always - 1; predicted taken
jne _1

LastWord:
This catches everything but multiple spaces - just add another loop before string processing. Currently, all spaces are treated as a string. Easiest solution is to ignore strings of length one.
Posted on 2003-08-18 11:15:03 by bitRAKE
Hey BitRake,
your code reminds me of the fiction point logic by The Svin.
Posted on 2003-08-18 11:46:46 by roticv

Hey BitRake,
your code reminds me of the fiction point logic by The Svin.
It would be okay if it worked on the last word. :(
Posted on 2003-08-18 12:38:14 by bitRAKE
Thanks for your ideas, they are very helpful
Posted on 2003-08-18 23:38:59 by nvm

Thanks for your ideas, they are very helpful
Your welcome!

I think this will complete the task: :)

- handles null pString
- skips leading spaces
- processes last string
;

; Delimited Array Pattern by Rickey Bowers Jr.
;
; - handles empty array
; - skips empty delimiter space in array
; - handles last array item (non-right-delimited item)
;
DELIMITER = " "
TERMINATOR = 0 ; Not Arnold - null ;)

mov edi, pString
mov esi, edi
jmp _2

_3: ; skip leading delimiters
cmp byte [esi], DELIMITER
je Next_Word

_4: ; ###################################
; do something with string ESI to EDI - 1
; (save EDI if modified)
; ###################################

Next_Word:
; save start of string
mov esi, edi

_1: cmp byte [edi], DELIMITER
lea edi, [edi+1]
; mostly not taken; predicted not taken
je _3

_2: cmp byte [edi], TERMINATOR
; taken always - 1; predicted taken
jne _1

LastWord:
; back to the null
dec edi
; equal for a zero length string
; greater for null pString
; less for last string
cmp esi, edi
jc _4


; By changing the delimiter and array advancement this pattern can be used for
; delimited array processing of many types of arrays.
...I'm happy with it. :)

Hint: This is a template that would work well with other tasks.
Let us just call it the Delimited Array Pattern.
Posted on 2003-08-19 00:08:32 by bitRAKE
The following is a pretty standard lexing pattern.
It sets ESI, so that it can be called again to get the next token.

In this form, there is an optimization that involves deleting the first two instructions and the last DEC instruction.

The subroutine allows the two options:

1) Calculate the number of characters in the token as (new EDI - old EDI).
2) Store a terminating byte (doesn't need to be 0) at .

; On entry:

; ESI = start of string to scan
; EDI = destination for storing copy of token
; On exit:
; ESI = pointer to terminating character
; EDI = points past last copied token character

readonetoken:
mov al,[esi] ; load next character
inc esi
skipwhiteloop:
cmp al,9 ; test for TAB
je skipwhitespace
cmp al,' '
je skipwhitespace
jmp endwhitespace
skipwhitespace:
mov al,[esi] ; load next character
inc esi
jmp skipwhiteloop
endwhitespace:

copytoken:
; The following tests can be for
; either valid or invalid token characters.
; If character is valid, jump to validchar,
; otherwise, jump to endtoken.
cmp al,0
je endtoken
cmp al,' '
je endtoken
cmp al,9 ; TAB
je endtoken

validchar:
mov [edi],al ; store valid character
inc edi
mov al,[esi] ; load next character
inc esi
jmp copytoken
endtoken:
; Every time we loaded AL for testing, we have incremented ESI
; past the loaded char.
; To point ESI to the last tested char (the terminating char),
; we must readjust it.
dec esi
ret
Posted on 2003-08-20 21:56:58 by tenkey