Tuesday, March 27, 2012

concatenation of strings in assembly X86

; concatenation of strings
;---------------------------------------------------------------------------

.model small

.data

message_display macro msg
mov dx,offset msg
mov ah,09h
int 21h
endm

msg1 db 10,13, "Enter the string $"
msg2 db 10,13, "Concatenated string is $"
msg3 db 10,13, "$"

string1 db 10h dup(0)
string2 db 10h dup(0)
string3 db 10h dup(0)
len1 db 00h
len2 db 00h

.code
mov ax,@data
mov ds,ax

message_display msg1

lea si,string1

next_char: mov ah,01h
int 21h
cmp al,0dh
jz l1

mov [si],al
inc si
inc len1
jmp next_char

l1: mov al,24h
mov [si],al

message_display msg3
message_display string1

message_display msg1

lea si,string2

next_char1: mov ah,01h
int 21h
cmp al,0dh
jz l2
mov [si],al
inc si
inc len2
jmp next_char1

l2: mov al,24h
mov [si],al

message_display msg3
message_display string2

message_display msg2
message_display msg3

mov bh,00h
mov bl,len1
mov ax,@data
mov ds,ax
mov es,ax

lea si,string1
lea di,string3

mov cx,bx
rep movsb

mov bh,00h
mov bl,len2
mov ax,@data
mov ds,ax
mov es,ax

lea si,string2

mov cx,bx
rep movsb

inc di
mov al,24h
mov [di],al

message_display string3

mov ah,4ch
int 21h
end

No comments:

Post a Comment