Assembly Language Flow Control Loop while condition is true in Intel syntax assembly


section .data
    msg db 'Hello, world!', 0xA
    len equ $ - msg
section .text
global _main
    mov rax, 0 ; This will be the current number
    mov rcx, 10 ; This will be the last number
    cmp rax, rcx
    jl .loopbody ; Jump to .loopbody if rax < rcx
    jge _exit ; Jump to _exit if rax ≥ rcx
    push rax ; Store the rax value for later use

    mov rax, 0x2000004 ; 4 for Linux
    mov rdi, 1 ; STDOUT
    mov rsi, msg
    mov rdx, len


    pop rax ; Take it back to rax

    inc rax ; Add 1 to rax. This is required since the loop must have an ending.    

    jmp _loop ; Back to loop
    ret    ; Return

This will execute .loopbody as long as rax < rcx.