ALP for string operations

, by Prashant Gunjal



4. Write 8086 ALP for the following operations on the string entered by the user.

(a) Enter the string b) Calculate length of string c) Reverse string d) Check palindrome e) Exit


.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 THE STRING",10,13,"2.LENGTH ",10,13,"3.REVERSE",10,13,"4.PALINDROME",10,13,"5.EXIT $"
msg2 db 10,13,"Enter your choice:$"
msg3 db 10,13,"Enter the string:$"
msg4 db 10,13,"Length of string is:$"
msg5 db 10,13,"Reverse of string is:   $"
msg6 db 10,13,"String is palindrome$"
msg7 db 10,13,"String is  not palindrome$"
str1 db 25,?,25 dup("$")
.code
mov ax,@data
mov ds,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: mov bl,str1+1
disp msg4
call prin
jmp main
p3: mov bl,str1+1
mov cl,bl
lea dx,str1+2
mov di,dx
disp msg5
again1: inc di
dec cl
jnz again1
dec di
again2: mov dl,[di]
mov ah,02h
int 21h
dec di
dec bl
jnz again2
jmp main
p4: mov bl,str1+1
mov cl,bl
lea dx,str1+2
mov si,dx
mov di,dx
loop1: inc di
dec cl
jnz loop1
dec di
loop2: mov dl,[di]
mov dh,[si]
cmp dl,dh
jne outt
dec di
inc si
dec bl
jnz loop2
disp msg6
jmp main
outt: disp msg7
jmp main
p5: mov ah,4ch
int 21h

prin proc near
mov cx,0204h
up1: 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 up1
ret
endp

end

0 comments: