You are on page 1of 21

section .

data

menumsg db 10,10,'Menu:',10

db 10,'1) Enter the String'

db 10,'2) Calculate the length'

db 10,'3) Reverse the String'

db 10,'4) Check Whether String is Palindrome or not'

db 10,'5) Exit',10

db 10,'Enter your Choice :'

menumsg_len equ $-menumsg

wrchmsg db 10,10,'Invalid Choice....Please try again!!!',10,10

wrchmsg_len equ $-wrchmsg

entmsg db 10,'Enter a String :'

entmsg_len equ $-entmsg

lmsg db 10,'Length of the String is :'

lmsg_len equ $-lmsg

revmsg db 10,'Reversed String is :'

revmsg_len equ $-revmsg

palmsg db 10,'String is a Palindrome!'

palmsg_len equ $-palmsg

npalmsg db 10,'String is not a Palindrome!'

npalmsg_len equ $-npalmsg

restmsg db 10,'Do you want to continue? (Y/N):'

restmsg_len equ $-restmsg

spacechar db 20h

section .bss

cnt resb 01

optionbuff resb 02

dispbuff resb 03

srcstr resb 10

revstr resb 10

string resb 0

%macro dispmsg 2

mov eax,04

mov ebx,01

mov ecx,%1

mov edx,%2

int 80h

%endmacro

%macro accept 2

mov eax,03

mov ebx,00

mov ecx,%1

mov edx,%2

int 80h

%endmacro

%macro acceptstr 1

mov eax,03

mov ebx,00

mov ecx,%1

int 80h

%endmacro

section .text

global _start

_start:

menu:

dispmsg menumsg,menumsg_len

accept optionbuff,02

cmp byte [optionbuff],'1'

jne case2

call entstr_proc

jmp exit1

case2:

cmp byte [optionbuff],'2'

jne case3

call length_proc

jmp exit1

case3:

cmp byte [optionbuff],'3'

jne case4

call reverse_proc

jmp exit1

case4:

cmp byte [optionbuff],'4'

jne case5

call pal_proc

jmp exit1

case5:

cmp byte [optionbuff],'5'

je exit

dispmsg wrchmsg,wrchmsg_len

jmp menu

exit1:

dispmsg restmsg,restmsg_len

accept optionbuff,02

cmp byte [optionbuff],'y'

jne y1

jmp menu

y1:

cmp byte [optionbuff],'Y'

jne exit

jmp menu

exit:

mov eax,01

mov ebx,00

int 80h

dispblk_proc:

mov ecx,cnt

rdisp:

push ecx

mov bl,[esi]

call disp8_proc

inc esi

dispmsg spacechar,1

pop ecx

loop rdisp

ret

entstr_proc:

dispmsg entmsg,entmsg_len

acceptstr srcstr

dec al

mov [cnt],al

ret

length_proc:

dispmsg lmsg,lmsg_len

mov bl,[cnt]

call disp8_proc

ret

reverse_proc:

mov ecx,00

mov esi,srcstr

mov edi,revstr

mov cl,[cnt]

add esi,ecx

sub esi,1

up2:

mov al,[esi]

mov [edi],al

inc edi

dec esi

loop up2

dispmsg revmsg,revmsg_len

dispmsg revstr,cnt

ret

pal_proc:

mov ecx,00

mov esi,srcstr

mov edi,revstr

mov cl,[cnt]

up3:

mov al,[esi]

mov bl,[edi]

cmp al,bl

jne exit2

inc esi

inc edi

loop up3

dispmsg palmsg,palmsg_len

jmp return

exit2:

dispmsg npalmsg,npalmsg_len

return:

ret

disp8_proc:

mov ecx,02

mov edi,dispbuff

dup1:

rol bl,4

mov al,bl

and al,0Fh

cmp al,09h

jbe dskip

add al,07h

dskip:

add al,30h

mov [edi],al

inc edi

loop dup1

dispmsg dispbuff,03

ret

OUTPUT:-

root@atharva-Inspiron-3542:/home/atharva# nasm -f elf32


palindrome.nasmroot@atharva-Inspiron-3542:/home/atharva# ld -o
palindrome palindrome.o -m elf_i386root@atharva-Inspiron3542:/home/atharva# ./palindrome

Menu:

1) Enter the String

2) Calculate the length

3) Reverse the String

4) Check Whether String is Palindrome or not

5) Exit

Enter your Choice :1

Enter a String :racecar

Do you want to continue? (Y/N):y

Menu:

1) Enter the String

2) Calculate the length

3) Reverse the String

4) Check Whether String is Palindrome or not

5) Exit

Enter your Choice :2

Length of the String is :07

Do you want to continue? (Y/N):y

Menu:

1) Enter the String

2) Calculate the length

3) Reverse the String

4) Check Whether String is Palindrome or not

5) Exit

Enter your Choice :3

Reversed String is :racecar

Do you want to continue? (Y/N):y

Menu:

1) Enter the String

2) Calculate the length

3) Reverse the String

4) Check Whether String is Palindrome or not

5) Exit

Enter your Choice :4

String is a Palindrome!

Do you want to continue? (Y/N):5

root@atharva-Inspiron-3542:/home/atharva#

You might also like