flat assembler
Message board for the users of flat assembler.

Index > Windows > split function?

Author
Thread Post new topic Reply to topic
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
Is there a split function that can be used in fasm? Even if it's api (i couldn't find it in winapi help file though).

I want to take a string and get all it's words into seperate variables (split at the spaces)

Thanks
Dr.X
Post 26 Apr 2004, 00:30
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
This function expects:
esi points to a szString
ecx length of szString

[edit]
Returns a number of splitted words in edx and pointers to each word in an array.

Code:
; This program is demonstrative only (workless)
; It is intended to be used with a debugger
; as for example OllyDbg

format PE GUI 4.0

section '.code' code readable executable

Start:
   mov  esi,TheString
   mov  ecx,TheLength
   mov  edi,TheWords
   call Tokenizer
   int3

Tokenizer:
   xor  edx,edx
.skipWhitespace:
   cmp  byte [esi],' '
   je   .skip
   cmp  byte [esi],09h
   je   .skip
   cmp  byte [esi],0Dh
   je   .skip
   cmp  byte [esi],0Ah
   jne  .doneWhitespace
.skip:
   inc  esi
   loop .skipWhitespace
.doneWhitespace:
   mov  [edi+edx*4],esi
   inc  edx
.seek:
   lodsb
   or   al,al
   je   .end
   cmp  al,' '
   je   .done
   cmp  al,09h
   je   .done
   cmp  al,0Ah
   je   .done
   cmp  al,0Dh
   je   .done
   cmp  al,ah
   je   .done
   loop .seek
   jmp  .end
.done:
   mov  byte [esi-1],0
   loop .skipWhitespace
.end:
   ret

section '.data' data readable writeable

TheWords  rd 100h ; Space reserved for 256 words
TheString db 'This is our string, the string we are going to use',0
TheLength =  $ - TheString
    


[/edit]


Last edited by pelaillo on 26 Apr 2004, 13:32; edited 1 time in total
Post 26 Apr 2004, 04:43
View user's profile Send private message Yahoo Messenger Reply with quote
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
I will have to study more. I think this one is too complex. I'm still a beginer. Perhaps I was asking if I can run before I can walk.

Thanks Pelaillo.
Dr.X
Post 26 Apr 2004, 12:21
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Dr X,

Please let me show it is not as complex as it seems at first sight.
I've changed my previous post in order to have a demonstrative view over it.
- Compile it with fasm
- Download (if you have not downloaded yet) OllyDbg from http://home.t-online.de/home/Ollydbg/
- Open the exe with OllyDbg and press F5 to show the processor screen. Then press F7 for a step debugging and look what happens on each step.

You will be changing this function to fit your own needs very soon Exclamation
Post 26 Apr 2004, 13:42
View user's profile Send private message Yahoo Messenger Reply with quote
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
Ok Pelaillo. I will try this when I get home (i'm at work right now)

When I said that it was complex, I only meant for me. I'm sure it is a good solution. I just have to study more. I'm new to asm (not just new to fasm but to the whole assembler thing in general). I'm still studying Vid's tutorials and reading Intro to Assembler by Draeden/VLA.

I will still try your suggestion. Thank you for the help.
Dr.X
Post 26 Apr 2004, 15:05
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Dr.X wrote:
When I said that it was complex, I only meant for me.


Well, you will learn assembler more easy if you try not to think this way. That was that pelaillo wanted to say. Assembler is actually more easy than it looks at first sight. Smile

Regards.
Post 26 Apr 2004, 18:04
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.