https://flatassembler.net/docs.php?article=manual#1.1
When operand is a data in memory, the address of that data (also any numerical expression, but it may contain registers) should be enclosed in square brackets or preceded by ptr operator. For example instruction mov eax,3 will put the immediate value 3 into the EAX register, instruction mov eax,[7] will put the 32-bit value from the address 7 into EAX and the instruction mov byte [7],3 will put the immediate value 3 into the byte at address 7, it can also be written as mov byte ptr 7,3. To specify which segment register should be used for addressing, segment register name followed by a colon should be put just before the address value (inside the square brackets or after the ptr operator).
To jest chyba dokumentacja FASM.
W NASM składnia też wymaga podania nawiasów kwadratowych do wzięcia efektywnego, czy jak to się nazywa adresu w pamięci, żeby móc się do niego odwołać.
2.2.2 NASM Requires Square Brackets For Memory References
https://www.nasm.us/doc/nasmdoc2.html#section-2.2.2
https://www.tortall.net/projects/yasm/manual/html/nasm-effaddr.html
Odpowiedzią na Twoje pytanie jest najprawdopodobniej to:
mov eax, [my_var]
lub:
mov dword [my_var], eax
ewentualnie:
mov [my_var], eax
Ogólnie to staraj się czytać tak równolegle dokumentację np. Intel'a i swojego assembler'a, ponieważ assembler'y mają swoje składnie i pewne specyficzne instrukcje.
https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf
global _main
extern _printf
section .data
my_var: dw 10, 0, 0
formatter: dw "%d", 0xa, 0
section .text
_main:
mov eax, [my_var]
push eax
push formatter
call _printf
pop eax
pop eax
section .bss
global _main
extern _printf
section .data
my_var: dw 10, 0, 0
formatter: dw "%d", 0xa, 0
section .text
_main:
mov eax, 50
mov dword [my_var], eax
push dword [my_var]
push formatter
call _printf
add esp, 8
section .bss
assembler: NASM, kompilacja pod Windows'em:
nasm -fwin32 name_file.asm && gcc name_file.obj && a
Pod Linux'em lekko zmodyfikowany wyżej kod można by skompilować tak:
nasm -o name_file.obj -felf32 name_file.asm && gcc -m32 name_file.obj -o name_file && ./name_file