I am writing an x86 program to print, one line at a time: 9, 8, 7, ..., 1, 0. It compiles, and the value of count is getting decremented (I checked on the gdb debugger). But when I run the program on the command line with ./myprogram, I see no output.
This is the code:
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
        global    _start
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
        section   .text     ; Start of our code
_start:
    mov byte [count], 9
decr_loop:
    ;; Print current count value
    mov rax, 4      ; The system call for write
    mov rdi, 1      ; File descriptor/ handle for stdout (console)
    mov rsi, count      ; Address for count variable
    mov rdx, 1      ; Number of bytes to write
    syscall         ; Call Linux kernel. Trigger the write
    ;; Print newline character
    mov rax, 4      ; The system call for write
    mov rdi, 1      ; Console
    mov rsi, newline        ; Address for newline variable
    mov rdx, 1              ; Number of bytes to write
    syscall         ; Call Linux kernel. Trigger the write
    ;; Decrease the count
    dec byte [count]
    ;; Compare count to zero. Jump if greater
    cmp byte [count], 0
    jg decr_loop
    ;; This code ends the program.
        mov       rax, 60                 ; system call for exit
        xor       rdi, rdi                ; exit code 0
        syscall                           ; invoke operating system to exit
; ------------------------------------------------------------------------------
    
; ------------------------------------------------------------------------------
        section   .data
newline:
    db 10                 ; The integer 10 is a newline char
count:
    db 9              ; init count as 9, dummy variable
; ------------------------------------------------------------------------------
