mov rax,[num]
Because num just holds a byte, better not read this as a qword. Use the movzx eax, byte [num]
instruction. You don't need the movzx rax, byte [num]
instruction because all writing to a dword register already zeroes the high dword anyway.
but how do I print out 2 digit numbers?
Next code can do just that, printing numbers from the range [10,99].
Note that there's a placeholder right in front of the newline.
section .data
num: db 12, 0, 10
section .text
global _start
_start:
movzx eax, byte [num] ; Value LT 100
xor edx, edx
mov ebx, 10
div ebx ; Quotient in EAX, Remainder in EDX
mov ah, dl
add ax, '00' ; Convert to ASCII
mov [num], ax ; Stores 'tens' followed by 'ones'
mov rax, 1
mov rdi, 1
mov rsi, num
mov rdx, 3 ; 3 instead of 2
syscall
For a general approach you could first study Displaying numbers with DOS. It explains the methodology, but of course you'll need to adapt the code to 64-bit.
Even better info is at https://stackoverflow.com/a/46301894.