ALP menu-driven program to perform the string operations (64-bit)
kw.asm
section.datamenumsgdb10,"———————————————————————————————————————————"db10,"ALPforthestringoperations"
db 10, "———————————————————————————————————————————"
db 10, "1.Enterthestring"
db 10, "2.Calculatethelength"
db 10, "3.Reversethestring"
db 10, "4.Checkwhetherstringispalindromeornot"
db 10, "5.Exit"
db 10, "———————————————————————————————————————————"
db 10, "EnteryourChoice"menumsg_len equ$-menumsgwrchmsgdb10,"Wrongchoiceentered...Pleasetryagain",10wrchmsg_len equ$-wrchmsgentmsgdb"Enterthestring"entmsg_len equ$-entmsglmsgdb10,"Lengthofthestringis"lmsg_len equ$-lmsgrevmsgdb10,"Reversestringis"revmsg_len equ$-revmsgpalmsgdb10,"Stringispalindrome"palmsg_len equ$-palmsgnpalmsgdb10,"Stringisnotpalindrome"npalmsg_len equ$-npalmsgspacechardb20hsection.bsscntresb01optionbuffresb02dispbuffresb03srcstrresb10revstrresb10stringresb0%macro display 4
movrax,%1movrdi,%2movrsi,%3movrdx,%4syscall%endmacro
section.textglobal_start_start:menu:display1,1,menumsg,menumsg_lendisplay0,0,optionbuff,02cmpbyte[optionbuff],"1"jnecase2callentstr_procjmpexit1case2:cmpbyte[optionbuff],"2"jnecase3calllength_procjmpexit1case3:cmpbyte[optionbuff],"3"jnecase4callreverse_procjmpexit1case4:cmpbyte[optionbuff],"4"jnecase5callpal_procjmpexit1case5:cmpbyte[optionbuff],"5"jeexitdisplay1,1,wrchmsg,wrchmsg_lenjmpmenuexit1:jmpmenujneexitexit:movrax,60movrdi,0syscallentstr_proc:display1,1,entmsg,entmsg_lendisplay0,0,srcstr,10decalmov[cnt],alretlength_proc:display1,1,lmsg,lmsg_lenmovbl,[cnt]calldisp8_procretreverse_proc:movrcx,00movrsi,srcstrmovrdi,revstrmovcl,[cnt]addrsi,rcxsubrsi,1up2:moval,[rsi]mov[rdi],alincrdidecrsiloopup2display1,1,revmsg,revmsg_lendisplay1,1,revstr,cntretpal_proc:movrcx,00movrsi,srcstrmovrdi,revstrmovcl,[cnt]up3:moval,[rsi]movbl,[rdi]cmpal,bljneexit2incrsiincrdiloopup3display1,1,palmsg,palmsg_lenjmpreturnexit2:display1,1,npalmsg,npalmsg_lenreturn:retdisp8_proc:movrcx,02movrdi,dispbuffdup1:rolbl,4moval,blandal,0Fhcmpal,09hjbedskipaddal,07hdskip:addal,30hmov[rdi],alincrdiloopdup1display1,1,dispbuff,03ret
Output
Note: It is mandatory to perform all the operations one by one, while executing this program
kodingwindow@kw:~$ nasm -felf64 kw.asm kodingwindow@kw:~$ ld kw.o && ./a.out
———————————————————————————————————————————
ALP for the string operations
———————————————————————————————————————————
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 the string LOL
———————————————————————————————————————————
ALP for the string operations
———————————————————————————————————————————
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 03
———————————————————————————————————————————
ALP for the string operations
———————————————————————————————————————————
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
Reverse string is LOL
———————————————————————————————————————————
ALP for the string operations
———————————————————————————————————————————
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 palindrome
———————————————————————————————————————————
ALP for the string operations
———————————————————————————————————————————
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 5
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.