flat assembler
Message board for the users of flat assembler.

Index > Main > working with strings in FASM

Author
Thread Post new topic Reply to topic
Fagotus



Joined: 15 May 2004
Posts: 8
Fagotus 06 Sep 2004, 12:22
Hi everybody!
So - one quastion - how can i work with a string in fasm?
for example -
we have:
string01 db 'cool-note'

we need:
string02 db 'cool'
string03 db 'note'
Can anyone help me, please?
Post 06 Sep 2004, 12:22
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 06 Sep 2004, 12:35
Post 06 Sep 2004, 12:35
View user's profile Send private message Yahoo Messenger Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 203
Location: Madrid - Spain
avcaballero 06 Sep 2004, 12:39
Can this one help you?

; Example by avcaballero
org 100h
; We move 4 bytes from string01 to string02 and string03
mov cx, 4
mov si, string01
mov di, string02
rep movsb
inc si
inc di
mov cx, 4
rep movsb
; We print string01, string02 and string03
mov ah, 9
mov dx, string01
int 21h
mov dx, string02
int 21h
mov dx, string03
int 21h
; We return to DOS
mov ax, 4C00h
int 21h

; Data
string01 db 'cool-note','$'
string02 rb 4 ;'cool'
db '$'
string03 rb 4 ;'note'
db '$'
Post 06 Sep 2004, 12:39
View user's profile Send private message Visit poster's website Reply with quote
Fagotus



Joined: 15 May 2004
Posts: 8
Fagotus 06 Sep 2004, 14:12
avcaballero, sorry - i meant that we scan this string untill we have some symbol (like _ or #, or maybe ) and we save the string before this symbol as STRING01 and the string after that symbol as STRING02.
Post 06 Sep 2004, 14:12
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 06 Sep 2004, 14:34
AT runtime or compile time??
Post 06 Sep 2004, 14:34
View user's profile Send private message Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 203
Location: Madrid - Spain
avcaballero 06 Sep 2004, 14:45
Something like this?

; Example by avcaballero
org 100h
cld
; We look for '-'
xor cx, cx
mov si, string01
$_Bucle:
cmp byte[si], '-'
jz $_Exit
inc si
inc cx
jmp $_Bucle
$_Exit:
push cx
; We move cx bytes from string01 to string02 and the rest to string03
mov si, string01
mov di, string02
rep movsb
inc si
inc di
pop cx
sub cx, lon
neg cx
rep movsb
; We print string01, string02 and string03
mov ah, 9
mov dx, string01
int 21h
mov dx, string02
int 21h
mov dx, string03
int 21h
; We return to DOS
mov ax, 4C00h
int 21h

; Data
string01 db 'cool-notess','$'
lon = $-string01
string02 rb 4 ;'cool'
db '$'
string03 rb 4 ;'note'
db '$'
Post 06 Sep 2004, 14:45
View user's profile Send private message Visit poster's website Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast 06 Sep 2004, 21:33
Code:
string01 db 'cool-note', 0
string01.size = $ - string01
    


Code:
      Cld
      Xor    Eax, Eax
      Mov    Ecx, string01.size
      Mov    Al, '-'               ; character of interest
      Mov    Edi, string01
Repne Scasb
      Jecxz  .notfound
      Mov    byte [Edi-1], 0
          
      ; now Edi contains pointer to string03 'note'
      ; string01 contains 'cool'
    
Post 06 Sep 2004, 21:33
View user's profile Send private message Visit poster's website Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer 06 Sep 2004, 22:27
You know... He may want this during compile time, not runtime...
Post 06 Sep 2004, 22:27
View user's profile Send private message Reply with quote
Fagotus



Joined: 15 May 2004
Posts: 8
Fagotus 07 Sep 2004, 03:32
Dragontamer - no, i meant runtime Very Happy
Wink Thanks everyone!!! i'll try it! Smile
Post 07 Sep 2004, 03:32
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.