%macro scall 4
  mov rax, %1
  mov rdi, %2
  mov rsi, %3
  mov rdx, %4
  Syscall
%endmacro
section .data
    menumsg db "Menu for string operations", 10d, 13d
    menumsg_len equ $-menumsg
    a db "1.Enter the String", 10d, 13d
    a1 equ $-a
    b db "2.Calulate the length of the string", 10d, 13d
    b1 equ $-b
    c db "3.Reverse the string", 10d, 13d
    c1 equ $-c
    d db "4.Exit", 10d, 13d
    d1 equ $-d
    
    m1 db "Enter the String: ", 10d, 13d
    l1 equ $-m1
    m2 db "The length of the string is: ", 10d, 13d
    l2 equ $-m2
    m3 db "Reversed string is: ", 10d, 13d
    l3 equ $-m3
    ;m4 db "Do you want to continue(y/n)", 10d, 13d
    ;l4 equ $-m4
    m5 db "Thank you for your using this.....", 10d, 13d
    l5 equ $-m5

    
section .bss
  accubuff resb 20
  accubuff_len resb 20
  acctlen resb 50
  revbuff resb 16
  choice resb 2
  char_ans resb 3
  choice2 resb 2
section .text
    global _start

_start:
   menu:
    scall 1,1,menumsg,menumsg_len
    
    scall 1,1,a,a1
    
    scall 1,1,b,b1
    
    scall 1,1,c,c1
    
    scall 1,1,d,d1
    
    scall 0,0,choice,2
    
    cmp byte[choice],'1'
    jne case2
    call enstr_proc
 jmp menu
case2: 
    cmp byte[choice],'2'
    jne case3
    call len_proc
 jmp menu
;-------------------------------------------------------------------------------------------------------------------------
case3:
   cmp byte[choice],'3'
   call reverse_proc
 jmp menu
;-----------------------------------------------------------------------------------------------------------------------  
case4: 
   cmp byte[choice],'4'
   call exit1
;-----------------------------------------------------------------------------------------
enstr_proc:
    scall 1,1,m1,l1
    scall 0,0,accubuff,accubuff_len

    dec rax
    mov [acctlen],rax
ret
   jmp menu
;--------------------------------------------------------------------------------------------------------------------------
len_proc:
  scall 1,1,m2,l2
  scall 1,1,acctlen,2
  mov rbx,[acctlen]
  call display_proc
  mov rsi,accubuff
  mov rcx, 0
    
loop:
    mov al,[rsi]
    cmp al,0Ah
    je next
    inc cx
    inc rsi
    jmp loop

next:
    mov ax,cx
    cmp ax,09h
    jbe label1
    add ax,07h
label1:
    add ax,30h
    mov rbp,char_ans
    mov [rbp],ax
    scall 1,1,char_ans,2
jmp menu 
;------------------------------------------------------------------------------------------------------------------------
reverse_proc:
   mov rsi,accubuff
   mov rdi,revbuff
   mov rcx,[acctlen]
   add rsi,rcx
   dec rsi
 again:
   mov al,[rsi]
   mov [rdi],al
   dec rsi
   inc rdi
   loop again

   scall 1,1,m3,l3
   scall 1,1,revbuff,[acctlen]

jmp menu
;------------------------------------------------------------------------------------------------------------------------
display_proc:
  display_proc:
    mov rbp,char_ans
    mov rcx, 2

up3:
    rol al, 04
    mov dl, al

    and dl, 0Fh

    cmp dl, 09h
    jbe next1
    add dl, 07

next1:
    add dl, 30h
    mov [rbp], dl
    inc rbp
    dec rcx

    jnz up3
    scall 1,1,char_ans,3

jmp menu
;----------------------------------------------------------------------------------------------------------------------
exit1:
   scall 1,1,m4,l4
   scall 0,0,choice2,2
   
   cmp byte[choice2],'y'
   jne caseB
   jmp menu

caseB:
   cmp byte[choice2],'n'
   scall 1,1,m5,l5
   mov rax,60
   mov rdi,0
   Syscall

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: