Write 8086 ALP to perform string manipulation. The strings to be accepted from the user is to be stored in
data segment of program_l and write FAR PROCEDURES in code segment program_2 for following
operations on the string:
(a) Concatenation of two strings (b) Number of occurrences of a sub-string in the given string Use PUBLIC
and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.
.model medium
.data
acc1 db 10,13,'enter string1: $'
acc2 db 10,13,'enter string2: $'
acc3 db 10,13,'enter substring: $'
con db 10,13,'concatenated string: $'
same db 10,13,'strings are same $'
diff db 10,13,'strings are different $'
sbstr db 10,13,'No. of SubString Occurances : $'
str1 db 15,?,15 dup('$')
str2 db 15,?,15 dup('$')
str3 db 31 dup('$')
str4 db 15,00,15 dup('$')
num db 00h
.code
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
gets macro str
lea dx,str
mov ah,0ah
int 21h
endm
start: public str1
public str2
public str3
public str4
public num
public same
public diff
extrn concat:far
extrn compare:far
extrn substring:far
mov ax,@data
mov ds,ax
mov es,ax
xor ax,ax
disp acc1
gets str1
disp acc2
gets str2
disp con
call far ptr concat
call far ptr compare
disp acc3
gets str4
disp sbstr
call far ptr substring
mov ah,4ch
int 21h
end start
ends
end
.model tiny
.code
disp macro msg1
lea dx,msg1
mov ah,09h
int 21h
endm
start: public concat
public substring
public compare
extrn str1:byte
extrn str2:byte
extrn str3:byte
extrn str4:byte
extrn num:byte
extrn same:byte
extrn diff:byte
concat proc far
mov cl,str1+1
mov ch,00h
lea si,str1+2
lea di,str3
cld
rep movsb
mov cl,str2+1
mov ch,00h
lea si,str2+2
cld
rep movsb
disp str3
ret
concat endp
compare proc far
lea si,str1+2
lea di,str2+2
mov cl,str1+1
cmp cl,str2+1
jne notsame
mov ch,00h
cld
rep cmpsb
jnz notsame
lea dx,same
mov ah,09h
int 21h
jmp exit_cmp
notsame:disp diff
exit_cmp:ret
compare endp
substring proc far
mov num,00h
lea si,str3
mov dl,str1+1
add dl,str2+1
mov dh,00h
reinit: mov cl,str4+1
mov ch,00h
lea di,str4+2
cld
nxtchar:cmpsb
jne mismatch
cmp cx,01h
jne skip
inc num
skip: dec dx
jz exitsbstr
dec cx
jnz nxtchar
jmp reinit
mismatch:
dec si
lea di,str4+2
mov cl,str4+1
mov ch,00h
dec dx
jz exitsbstr
cmpsb
jne reinit
dec cx
jmp nxtchar
exitsbstr:
mov bl,num
call print
ret
substring endp
print proc near
mov ch,02h
mov cl,04h
again: rol bl,cl
mov dl,bl
and dl,0fh
cmp dl,09h
jbe skip1
add dl,07h
skip1: add dl,30h
mov ah,02h
int 21h
dec ch
jnz again
ret
print endp
end
data segment of program_l and write FAR PROCEDURES in code segment program_2 for following
operations on the string:
(a) Concatenation of two strings (b) Number of occurrences of a sub-string in the given string Use PUBLIC
and EXTERN directive. Create .OBJ files of both the modules and link them to create an EXE file.
- str1.asm
.model medium
.data
acc1 db 10,13,'enter string1: $'
acc2 db 10,13,'enter string2: $'
acc3 db 10,13,'enter substring: $'
con db 10,13,'concatenated string: $'
same db 10,13,'strings are same $'
diff db 10,13,'strings are different $'
sbstr db 10,13,'No. of SubString Occurances : $'
str1 db 15,?,15 dup('$')
str2 db 15,?,15 dup('$')
str3 db 31 dup('$')
str4 db 15,00,15 dup('$')
num db 00h
.code
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
gets macro str
lea dx,str
mov ah,0ah
int 21h
endm
start: public str1
public str2
public str3
public str4
public num
public same
public diff
extrn concat:far
extrn compare:far
extrn substring:far
mov ax,@data
mov ds,ax
mov es,ax
xor ax,ax
disp acc1
gets str1
disp acc2
gets str2
disp con
call far ptr concat
call far ptr compare
disp acc3
gets str4
disp sbstr
call far ptr substring
mov ah,4ch
int 21h
end start
ends
end
- str2.asm
.model tiny
.code
disp macro msg1
lea dx,msg1
mov ah,09h
int 21h
endm
start: public concat
public substring
public compare
extrn str1:byte
extrn str2:byte
extrn str3:byte
extrn str4:byte
extrn num:byte
extrn same:byte
extrn diff:byte
concat proc far
mov cl,str1+1
mov ch,00h
lea si,str1+2
lea di,str3
cld
rep movsb
mov cl,str2+1
mov ch,00h
lea si,str2+2
cld
rep movsb
disp str3
ret
concat endp
compare proc far
lea si,str1+2
lea di,str2+2
mov cl,str1+1
cmp cl,str2+1
jne notsame
mov ch,00h
cld
rep cmpsb
jnz notsame
lea dx,same
mov ah,09h
int 21h
jmp exit_cmp
notsame:disp diff
exit_cmp:ret
compare endp
substring proc far
mov num,00h
lea si,str3
mov dl,str1+1
add dl,str2+1
mov dh,00h
reinit: mov cl,str4+1
mov ch,00h
lea di,str4+2
cld
nxtchar:cmpsb
jne mismatch
cmp cx,01h
jne skip
inc num
skip: dec dx
jz exitsbstr
dec cx
jnz nxtchar
jmp reinit
mismatch:
dec si
lea di,str4+2
mov cl,str4+1
mov ch,00h
dec dx
jz exitsbstr
cmpsb
jne reinit
dec cx
jmp nxtchar
exitsbstr:
mov bl,num
call print
ret
substring endp
print proc near
mov ch,02h
mov cl,04h
again: rol bl,cl
mov dl,bl
and dl,0fh
cmp dl,09h
jbe skip1
add dl,07h
skip1: add dl,30h
mov ah,02h
int 21h
dec ch
jnz again
ret
print endp
end
No comments:
Post a Comment