MIT String Operations

%macro Display 2
    mov rax,1
    mov rdi,1
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro
%macro Accept 2
    mov rax,0
    mov rdi,0
    mov rsi,%1
    mov rdx,%2
    syscall
%endmacro

section .data
    choice db 10,"please enter the choice:: "
    db 10,"1:Accept string"
    db 10,"2:display the length of string"
    db 10,"3:revers the string"
    db 10,"4:check the string is palindrome or not"
    db 10,"5:Exit" ,10,10
       
    choice_len equ $-choice

    msg db 10,"please enter the string:: "
    msg_len equ $-msg

    lenmsg db 10,"length of the string is:: "
    len_msg equ $-lenmsg

    revmsg db 10,"revers string is:: "
    revmsg_len equ $-revmsg

    palimsg db 10,"string is palindrom......"
    palimsg_len equ $-palimsg

   
   
    notpalimsg db 10,"string is not palindrom......"
    notpalimsg_len equ $-notpalimsg
   

section .bss
    string resb 50
    stringlen equ $-string

    revstring resb 50
    str_length resq 1

    length resb 16
    cho resb 2

section .text
    global _start
_start:

    Display choice,choice_len
    Accept cho,2
   
    cmp byte[cho],35h
    je exit

    cmp byte[cho],31h
    je acc_string
   

    cmp byte[cho],32h
    je dis_len

    cmp byte[cho],33h
    je str_reverse
   
    cmp byte[cho],34h
    je str_palindrom

    jmp exit

acc_string:
    Display msg,msg_len
    Accept string,stringlen
    dec rax
    mov [str_length],rax

jmp _start
   
dis_len:
    Display lenmsg,msg_len
    mov rbx,[str_length]
    call display_proc

jmp _start

str_reverse:

    mov rsi,string
    mov rdi,revstring
    mov rcx,[str_length]
    add rsi,rcx
    dec rsi
again:
    mov al,[rsi]
    mov [rdi],al
    dec rsi
    inc rdi
    loop again

    Display revmsg,revmsg_len
    Display revstring,[str_length]
jmp _start

str_palindrom:
    mov rsi,string
    mov rdi,revstring
    mov rcx,[str_length]

    l2:mov al,[rsi]
    mov bl,[rdi]
    cmp al,bl
    je l1
    Display notpalimsg,notpalimsg_len
    jmp _start
    l1:inc rsi
    inc rdi
    loop l2

    Display palimsg,palimsg_len

    jmp _start

exit:
    mov rax,60
    mov rbx,0
    syscall


display_proc:
    mov rdi,length
    mov rcx,16

p3:
    rol  rbx,4
    mov dl,bl
    and dl,0fh
    cmp dl,09h
    jg p1
    add dl,30h
jmp p2
p1:
     add dl,37h
    p2:mov [rdi],dl
    inc rdi
    loop p3

    Display length,16
    ret


SHARE
    Blogger Comment
    Facebook Comment