I want to display the least significant digit with an assembly program on nasm/macho-64:
%define SYSCALL_WRITE 0x2000004
%define SYSCALL_EXIT 0x2000001
SECTION .data
digit db 0,10
SECTION .text
global _start
_start:
add rax, 48
mov [digit], al
mov rax, SYSCALL_WRITE
mov rdi, 1
mov rsi, digit
mov rdx, 2 ;length (of 48)
syscall
mov rax, SYSCALL_EXIT
mov rdi, 0
syscall
Here, al is used because it contains the lowest order byte of rax. I figured out from similar questions that 64-bit assembly doesn't have the [] syntax. I then tried to use
lea digit, al
and
lea [digit], al
but both gave me "invalid combination of opcode and operation" error. I also tried mov rax instead of add rax. What should I do in order to load/move the least significant digit of rax into my digit variable?
Thank you.