ALP using far procedure for string operations

, by Prashant Gunjal


5. 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.

;PROGRAM 1


extrn concat:far
extrn substring:far
public str1
public str2
public msg5
public msg7
public msg8
.model small
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
.data
msg1 db 10,13,10,13,"MENU",10,13,"1.Enter 1st string",10,13,"2.Enter 2nd string",10,13,"3.Concatenate",10,13,"4.Substring ",10,13,"5.exit $"
msg2 db 10,13,"Enter your choice:$"
msg3 db 10,13,"Enter the 1st string:$"
msg4 db 10,13,"Enter the 2nd string:$"
msg5 db 10,13,"Concatenate string is:$"
msg6 db 10,13,"substring is found $"
               msg7 db 10,13,"substring is not found $"
               msg8 db 10,13,"no. of occurence: $"
               str1 db  25,?,25 dup("$")
str2  db 25,?,25 dup("$")
             
.code
              mov ax,@data
mov ds,ax
mov es,ax
main: disp msg1
disp msg2
mov ah,01h
int 21h
cmp al,31h
je p1
cmp al,32h
je p2
cmp al,33h
                  je p3
               cmp al,34h
je p4
               cmp al,35h
je p5
jmp main
p1: disp msg3
lea dx,str1
mov ah,0Ah
int  21h
jmp main

p2: disp msg4
lea dx,str2
mov ah,0Ah
int  21h
jmp main
p3: call concat
                 jmp main

p4: call substring
                 jmp main

p5:          mov ah,4ch      
int 21h
              end

; PROGRAM 2


extrn str1
extrn str2
extrn msg5
extrn msg7
extrn msg8

public concat
public substring
disp macro msg
      lea dx,msg
       mov ah,09h
       int 21h
endm
.model small
.data
 count2 db ?
add_off dw ?
.code
concat proc far
disp msg5
lea si,str1
lea di,str2
inc si
inc di

mov cl,[si]
mov bl,[di]
mov ch,cl
up11: inc si
dec ch
jnz up11
inc si
inc di
mov bh,bl
up12: mov al,[di]
mov [si],al
inc si
inc di
dec bh
jnz up12

add bl,cl
lea si,str1
inc si
inc si


up13: mov dl,[si]
mov ah,02h
int 21h
inc si
dec bl
jnz up13
             
               ret
              endp

substring proc far
lea si,str1
lea di,str2
  inc si
inc di
               mov bl,00h
               mov cl,[si]
mov ch,[di]
mov count2,ch
sub cl,ch
add cl,01h
inc si
               inc di
up3: mov bh,[si]
cmp bh,[di]
  jne out1
  mov add_off,si
up1: mov bh,[si]
cmp bh,[di]
  jne out3
               inc si
inc di
dec ch
jnz up1
inc bl
out3: mov ch,count2
mov si,add_off
out1: inc si
                lea di,str2
                 inc di
inc di
dec cl
 jnz up3
               cmp bl,00h
                 jne down
                  disp msg7
                   jmp main1
down: disp msg8
         mov cx,0204h
again: rol bl,cl
      mov dl,bl
      and dl,0fh
      cmp dl,09h
      jbe skip
      add dl,07h
skip: add dl,30h
      mov ah,02h
      int 21h
      dec ch
      jnz again
   
     main1:      ret
      endp  
end  

 OUTPUT
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\student>cd\tasm

C:\tasm>tasm pg1.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   pg1.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  440k


C:\tasm>tasm pg2.asm
Turbo Assembler  Version 2.0  Copyright (c) 1988, 1990 Borland International

Assembling file:   pg2.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  441k


C:\tasm>tlink pg1 pg2
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack

C:\tasm>pg1


MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:1
Enter the 1st string:kaka

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:2
Enter the 2nd string:kaki

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:3
Concatenate string is:kakakaki

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:4
substring is not found

MENU
1.Enter 1st string
2.Enter 2nd string
3.Concatenate
4.Substring
5.exit
Enter your choice:5
C:\tasm>

0 comments: