%macro scall 4
mov rax,%1 ;function number for writing or o/p data
mov rdi,%2 ;file descriptor id for monitor
mov rsi,%3 ;starting address of string to be displayed
mov rdx,%4 ;number of bytes to be displayed
syscall
%endmacro
section .data ;initialized variable declaration
menu db 10d,13d,"!!!!MENU!!!!" ;messages
db 10d,"1.ENTER A STRING"
db 10d,"2.LENGTH OF STRING"
db 10d,"3.REVERSE STRING"
db 10d,"4.CHECK STRING IS PALLINDROME OR NOT"
db 10d,"5.EXIT"
db 10d,"ENTER YOUR CHOICE:"
menulen equ $-menu
newline db 10
m1 db 10d,"ENTER STRING:"
l1 equ $-m1
m2 db 10d,"LENGTH OF STRING:"
l2 equ $-m2
m3 db 10d,"REVERSE STRING:"
l3 equ $-m3
m4 db 10d,"STRING IS PALLINDROME!!"
l4 equ $-m4
m5 db 10d,"STRING IS NOT PALLINDROME!!"
l5 equ $-m5
m6 db 10d,"!!!!!STRING OPERATION COMPLETED!!!!!"
l6 equ $-m6
section .bss ;uninitialized variable declaration
string resb 50
string2 resb 50
len resb 16
choice resb 16
answer resb 16
section .text
global _start ;entry point for program
_start: ;program code goes here
scall 1,1,menu,menulen ;display the menu
scall 0,0,choice,2 ;read the choice from the user
cmp byte[choice], '1'
je enter_string ;if choice =1 jump to enter_string procedure
cmp byte[choice], '2'
je display_length
cmp byte[choice], '3'
je string_reverse
cmp byte[choice], '4'
je pallindrome
cmp byte[choice], '5'
je exitcall
enter_string:
scall 1,1,m1,l1 ;enter the string
scall 0,0,string,50 ;read the string
dec rax
mov [len],rax
scall 1,1,newline,1
jmp _start
display_length:
scall 1,1,m2,l2
mov rax,[len]
call display
jmp _start
string_reverse:
call stringreverse
scall 1,1,m3,l3
scall 1,1,string2,[len]
scall 1,1,newline,1
jmp _start
pallindrome:
call stringreverse
mov rsi,string
mov rdi,string2
mov rcx,[len]
call loop3
jmp _start
exitcall:
scall 1,1,m6,l6
scall 1,1,newline,1
mov rax,60
mov rdi,0
syscall
display:
mov rsi,answer+15
mov rcx,16
loop1:
mov rdx,0
mov rbx,16
div rbx
cmp dl,09h
jbe skip1
add dl,07h
skip1:
add dl,30H
mov [rsi],dl
dec rsi
dec rcx
jnz loop1
scall 1,1,answer,16
scall 1,1,newline,1
ret
stringreverse:
mov rsi,string
mov rdi,string2
mov rcx,[len]
add rdi,rcx
dec rdi
loop2:
mov al,[rsi]
mov [rdi],al
dec rdi
inc rsi
loop loop2
ret
loop3:
mov al,[rsi]
mov bl,[rdi]
inc rsi
inc rdi
cmp al,bl
jne skip2
loop loop3
scall 1,1,m4,l4
scall 1,1,newline,1
jmp _start
skip2:
scall 1,1,m5,l5
scall 1,1,newline,1
ret
To embed this project on your website, copy the following code and paste it into your website's HTML: