Search This Blog

Tuesday, February 11, 2014

Assembly Language Program for String Manipulation in 8086 assembly language

DATA SEGMENT   
        MSG1 DB 10,13,'ENTER String :$'
        MSG2 DB 10,13,'Lenght of string is : $'
        MSG3 DB 10,13,'Reverse of String is : $'
        MSG4 DB 10,13,'Concated String is :$'
        str1 db 10 dup(0)
        str2 db 10 dup(0)
DATA ENDS

CODE SEGMENT
        ASSUME CS:CODE,DS:DATA
START:
        MOV AX,DATA
        MOV DS,AX
       
        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str1
       
 BACK:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back


     ; code to find out lenght
      mov ch,00h
      Mov si, offset str1
 next:
      inc ch
      mov al,[si]
      inc si
      cmp al,'$'    
      jnz next

      DEC si
      dec si
      dec ch
      Mov di, offset str2
backward:
      mov al,[si]  
      mov [di],al
      dec si
      inc di
      dec ch
      jnz backward
      mov al,'$'
      mov [di],al
     
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG3
      INT 21H
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,str2
      INT 21H

      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END

No comments:

Post a Comment