flat assembler
Message board for the users of flat assembler.

Index > Main > Putting 2 strings together

Author
Thread Post new topic Reply to topic
Christopher D



Joined: 25 Jun 2005
Posts: 17
Christopher D
Can anyone PLEASE show me how I could put to strings together?
and, as far as I know i think theres 2 methods, one is something with an
%s and one is where you just add it onto the end of a string, could someone please show me both of these ways?

Thanks,
Smile
Post 26 Jun 2005, 04:45
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith
you can also use windows api "lstrcat" in kernel32 !

_________________
Je suis sur de 'rien', mais je ne suis pas sur du 'tout'.
Post 26 Jun 2005, 07:23
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
Code:
szFormat db "%s%s",0
szText1 db "line1",0
szText2 db "line2",0
...
szBuffer rb 1024
...

cinvoke wsprintf,szBuffer,szFormat,szText1,szText2
    


as said flaith it is better to use lstrcat
Post 26 Jun 2005, 13:28
View user's profile Send private message Reply with quote
shaolin007



Joined: 03 Sep 2004
Posts: 65
shaolin007
Another way is to use c function strcat(). Just import it like the strcmp() in previous post.

Code:
cinvoke strcmp, string 1, string 2
    


String2 is added to string1.
Post 26 Jun 2005, 13:37
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Hy, i just wrote these, they work...

Code:
macro bdisplay .__stringvar002 {
mov si,.__stringvar002
mov bl,10
call bwritestring
}

org 100h

push es
push ds
pop es

;testing strcat0b
bdisplay _strcat0b

bdisplay _string1
bdisplay _plusstring
bdisplay _string2
bdisplay _equalstring

mov di,_string1
mov si,_string2

call strcat0b

bdisplay si

call bendline


;testing stradd0b
bdisplay _stradd0b

bdisplay _string1
bdisplay _plusstring
bdisplay _string2
bdisplay _equalstring

mov di,_string1
mov si,_string2

call stradd0b

bdisplay si

call bendline

;testing strcat0b now with modified string1
bdisplay _strcat0b

bdisplay _string1
bdisplay _plusstring
bdisplay _string2
bdisplay _equalstring

mov di,_string1
mov si,_string2

call strcat0b

bdisplay si

call bendline


xor ax,ax ; waitkey
int 16h

pop es
int 20h

_string1: db 'Flat',0
times 128 db 0 ; we resetve bytes for proc stradd
_string2: db 'assembler',0
_plusstring: db ' + ',0
_equalstring: db ' = ',0

_strcat0b: db ' strcat0b: ',13,10,0
_stradd0b: db ' stradd0b: ',13,10,0

bwritestring: ; Writes a 0 terminated string to screen ( string is at ds:si )
push ax bx
mov bx,7 ; use video page 0, normal white
mov ah,$e
localloop:
lodsb
or al,al
jnz next_char
pop bx ax
ret
next_char:
int 10h
jmp localloop

bendline: ; ends the line ( adds y loc = 1 x loc = 0 )
push ax bx ; returns:  AX = 0xE0A ; BX = 7
mov bx,7
mov ax,$E0D
int 10h
mov al,$A
int 10h
pop bx ax
ret


;------------------------------------------------------------
strcat0b: ; append string, 0 terminated: input: es:di = string1, ds:si=string2, output: ds:si=string1+string2+#0
xor ebx,ebx
mov bx,.tmpstr
.copy01:
mov al,[es:di]
or al,al
jz .copy02
mov [ebx],al
inc di
inc ebx
jmp .copy01
.copy02:
lodsb
mov [ebx],al
inc ebx
or al,al
jz .done2
jmp .copy02
.done2:
mov si,.tmpstr
ret
.tmpstr: times 256 db 0

stradd0b: ; append string2 onto string1 end, 0 terminated: input: es:di = string1, ds:si=string2, output: string1 with string2 apended at ds:si
; (reserve bytes at the end of string1!)
mov bx,di
.getend01:
mov al,[es:di]
or al,al
jz .copy02
inc di
jmp .getend01
.copy02:
lodsb
stosb
or al,al
jz .done2
jmp .copy02
.done2:
mov si,bx
ret
    
Post 26 Jun 2005, 15:14
View user's profile Send private message Visit poster's website Reply with quote
Christopher D



Joined: 25 Jun 2005
Posts: 17
Christopher D
Thanks
Post 26 Jun 2005, 17:34
View user's profile Send private message Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
Here is another approach.

Code:
format PE CONSOLE
include 'win32ax.inc'

.data

        src             db 'a man from Kent',0
        srclen  dd $-src
        dest            db 'There once was ',0
        buffer  rb 30
        destlen dd buffer-dest-1        ;extra -1 to skip destination zero terminated byte 
        strm            db 'Message',0

.code

start:

        mov     esi, src                ; source address in esi
        mov     ecx, [srclen]   ; length of source in ecx
        inc     ecx                     ; include the 0 termination byte
        mov     edi, dest               ; destination in edi
        add     edi, [destlen]  ; start at end of destination

        rep movsb
        
        push    0
        push    strm
        push    dest
        push    0
        call    [MessageBox]
        push    0
        call    [ExitProcess]

.end start
    


If you do use something like this, make sure the destination buffer can hold all the bytes.
Post 26 Jun 2005, 17:56
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-2020, Tomasz Grysztar.

Powered by rwasa.