Professional Documents
Culture Documents
PAIAss 4
PAIAss 4
ROLL NO :29
BATCH: S2
TITLE: Write menu driven ALP to perform string manipulations. The strings to be accepted from the
user is to be stored in code segment Module_1 and write FAR PROCEDURES in code segment
Module_2 to perform any two of the following string operations:
1)Concatenation of two strings.
2)Finding Number of occurrences of a sub-string in the given string
Module_1
.model small
.data
menu db 10d,13d," MENU"
db 10d,"1. Concatenation"
db 10d,"2. Substring"
db 10d,"3. Exit"
db 10d,"Enter your choice: $"
.code
;concat and substring procedures will be defined in external files
extrn concat:far
extrn substring:far
mov ax,@data
mov ds,ax
main:
lea dx,menu
mov ah,09h ;display menu string
int 21h
cmp al,'1'
je case1
cmp al,'2'
je case2
jmp exit
.code
public concat,substring
;procedures scope has been made public
;accessible to other segments also
;*******************CONCATENATION PROCEDURE*****************
concat proc
mov ax,@data
mov ds,ax
lea si,s1
lea di,s3
inc si
mov cl,[si] ;length of s1 string
scall nwline,09h
scall m3,09h ;display m3 string
scall s3,09h ;display concatenated string
;****************SUBSTRING PROCEDURE**********************
substring proc
mov ax,@data
mov ds,ax
lea si,s1
inc si
mov cl,[si] ;take length of s1 string in cl
inc si
lea di,s2
inc di
mov ch,[di] ;take length of s2 string in cl
inc di
mov dh,ch ;backup of ch register
loop3:
mov al,[si]
mov bp,si ;backup of si pointer
cmp al,[di]
je loop4
inc si
dec cl ;counter for main string
jnz loop3
mov dl,[count]
cmp dl,0 ;dl=0 implies no string found
je fail
jmp result
loop4:
dec ch ;counter for sub-string
cmp ch,0
je success
inc si
inc di
mov al,[si]
cmp al,[di]
je loop4 ;continue this loop till string are same
success:
add [count],01
lea di,s2
add di,2 ;move di to string place
inc bp
mov si,bp ;restore si from bp
dec cl
mov ch,dh ;restore ch from dh
fail:
scall m5,09h ;display m5
ret ;return from procedure
result:
scall m4,09h ;display m4 string
scall m6,09h ;display m6 string
mov dl,[count]
add dl,30h
mov ah,02h ;display dl contents
int 21h
ret ;return from procedure
endp ;end of procedure
end ;end of Program
OUTPUT:
C:\TASM1~1.4\Tasm>p1.exe
MENU
1. Concatenation
2. Substring
3. Exit
Enter your choice: 1
coe
MENU
1. Concatenation
2. Substring
3. Exit
Enter your choice: 2
string: coe
Second String is
Substring. No. Of
Occurrence: 1
MENU
1. Concatenation
2. Substring
3. Exit
Enter your choice: 3