SE Comp Sem-II MIL Prac-7 (String Operation-NEAR)

;string operations using near proc

disp macro msg
   mov ah,09h
   lea dx,msg
   int 21h

endm

.model small
.stack
.data
str1  db 25,?,25 dup('$')
str2  db 25,?,25 dup('$')
str3  db 25,?,25 dup('$')
ch0   db 10,13,'MENU $'
ch1   db 10,13,'1.INPUT $'
ch2   db 10,13,'2.LENGTH $'
ch3   db 10,13,'3.REVERSE $'
ch4   db 10,13,'4.PALINDROME $'
ch5   db 10,13,'5.EXIT $'
msg1  db 10,13,'ENTER STRING 1: $'
msg2  db 10,13,'ENTER STRING 2: $'
msg3a  db 10,13,'LENGTH OF STRING 1: $'
msg3b  db 10,13,'LENGTH OF STRING 2: $'
msg4  db 10,13,'REVERSE: $'
msg5  db 10,13,'STRING IS PALINDROME $'
msg6  db 10,13,'STRING IS NOT PALINDROME $'

.code
    main proc
        mov ax,@data
        mov ds,ax
        mov es,ax

m:      disp ch0
        disp ch1
        disp ch2
        disp ch3
        disp ch4
        disp ch5

        mov ah,01h
        int 21h

        cmp al,'1'
        je inp

        cmp al,'2'
        je len

        cmp al,'3'
        je rev

        cmp al,'4'
        je pal

        cmp al,'5'
        je endd

inp:    call input
        jmp m
len:    call leng
        jmp m
rev:    call reverse
        jmp m
pal:    call palin
        jmp m
endd:   mov ax,4c00h
        int 21h
endp main

;input
input proc near
    disp msg1
    mov ah,0ah
    lea dx,str1
    int 21h

    disp msg2
    mov ah,0ah
    lea dx,str2
    int 21h
ret
endp

;length
leng proc near
    disp msg3a
    mov dl,str1+1          ;length of str1
    add dl,30h
    mov ah,02h
    int 21h

    disp msg3b
    mov dl,str2+1          ;length of str1
    add dl,30h

    mov ah,02h
    int 21h
ret
endp

;reverse
reverse proc near
    mov cl,str1+1              ;length of string
    sub cl,01h
    lea si,str1+2              ;copying string to si
    repz movsb

      mov cl,str1+1            ;length of string
      lea di,str3+2            ;offset of desti string
lop:  mov dx,[si]
      mov ah,02h
      int 21h
      mov [di],dx              ;storing to di
      dec si
      inc di
      dec cl
      jnz lop

ret
endp

;palindrome
palin proc near
      call reverse
      lea di,str3+2
      lea si,str1+2
      mov cl,str1+1
lp1:  mov al,byte ptr[di]
      mov bl,byte ptr[si]
      cmp al,bl
      je loop1
      disp msg6
      jmp skip
loop1:
      dec cl
      inc si
      inc di
      cmp cl,00h
      jnz lp1
      disp msg5

skip:
      ret
endp

end

No comments:

Post a Comment