Here's my code:
section .data
digit db 0,10
section .text
global _start
_start:
call _printRAXDigit
mov rax, 60
mov rdx, 0
syscall
_printRAXDigit:
add rax, 48
mov [digit], al
mov rax, 1
mov rdi, 1
mov rsi, digit
mov rdx, 2
syscall
ret
I have a question about the difference between [digit]
and digit
.
I have learned that labels (like digit in the code), represent the memory address of the data, and the operator "[]" acts like something to dereference the pointer, so it will load the value that the label points at to the destination.
For instance, mov rax, [digit]
will throw 0 to the rax
register because digit points at the first element of the data (in this case, the integer 0).
However, in my code, it works when I write mov [digit], al
, which means "load the value stored in al
to the memory address digit", but I have no idea why we should use "[]" in this case. The first argument of mov
must be a destination (like a register or a memory address), so I think it should be mov digit, al
rather than mov [digit], al
. It doesn't make sense to me why we use a value to get the value from another place rather than use a memory address to get the value.
So that's all of my question. Please give me any response about where my thinking is wrong or any correction about my concept of labels.