Search This Blog

Tuesday, February 11, 2014

Program to find out Lenght of String 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

      add ch,'0'

      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG2
      INT 21H

      mov ah, 2
      mov dl, ch
      int 21h

      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END




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

        MOV AH,09H              ;DISPLAY MESG
        LEA DX,MSG1
        INT 21H
   
        Mov si, offset str2
       
 BACK1:  MOV Ah,01H            ;READ FROM KBD
        INT 21H
        mov [si], al
        inc si
        cmp al,'$'
        jnz back1


        Mov si, offset str1
 next:
      mov al,[si]
      inc si
      cmp al,'$'    
      jnz next               
     
     DEC si
     
     
      Mov di, offset str2
backward:
      mov al,[di]  
      mov [si],al
      inc si
      inc di
      cmp al,'$'
      jnz backward

          
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,MSG4
      INT 21H
      MOV AH,09H              ;DISPLAY MESG
      LEA DX,str1
      INT 21H



      MOV AH,4CH
      INT 21H

CODE ENDS
END START
END




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