%macro print 2
    mov rax,1 ; Function 1 - write
    mov rdi,1 ; To stdout
    mov rsi,%1 ; String address
    mov rdx,%2 ; String size
    syscall ; invoke operating system to WRITE
%endmacro

%macro read 2
    mov rax,0 ; Function 0 - Read
    mov rdi,0 ; from stdin
    mov rsi,%1 ; buffer address
    mov rdx,%2 ; buffer size
    syscall ; invoke operating system to READ
%endmacro

section .data
    m1 db "Enter String:"
    l1 equ $-m1
    
    m2 db 10,"Length of String is: ",
    l2 equ $-m2
    
    m3 db 10,"Reversed String: "
    l3 equ $-m3

section .bss
    string resb 50
    string2 resb 50
    length resb 16
    answer resb 16
    
section .text
    global _start
    
_start:

    print m1,l1
    read string,50
    ;length is returned in rax
    ;decrement once to remove count of Enter character
    ;dec rax

    mov [length],rax
    print m2,l2
    mov rax,[length]
    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
    print answer,16

    mov rsi,string
    mov rdi,string2
    mov rcx,[length]
    add rdi,rcx
    dec rdi

loop2:
    mov al,[rsi]
    mov [rdi],al
    dec rdi
    inc rsi
    loop loop2
    
    print m3,l3
    print string2,[length]
    mov rax,60
    mov rdx,0
    syscall

Embed on website

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