TL;DR
Is [memloc]
referring to the value or the address? If it's referring to either, then why does it work both as a value and an address? (see code below, lines 4 and 5)
Full question...
Sorry for the long question. I'm confused by label dereferencing in NASM. Take this example:
01| section .text
02| ; exiting the program with exit code "15"
03|
04| mov [memloc], 15 ; move 15 into memloc
05| push [memloc] ; push memloc on stack
06| mov eax, 1 ; prepare exit syscall
07| call kernel ; invoke syscall
08|
09| section .data
10| memloc: dd 0 ; let's say this is at address 0x1234
When I run it, it exits with code 15. It works!
...but why? Shouldn't memlock
be without braces line 4, where push
presumably expects a destination?
For example:
The mov
instruction at line 04
moves the value 15 to the ADDRESS of memloc:
mov [memloc], 15 ; move 15 into mem @memloc
But line 05
pushes the VALUE stored at memloc onto the stack:
push [memloc] ; push value @memloc on stack
So, is [memloc]
the value (15
) or the address (0x1234
)? What happens in theory if you mov memloc, 15
instead?
Thank you in advance.