问题
I've defined these global variables but I cant seem to change their value in the code. I need other C modules to have access to these variables.
global base
global freep
SECTION .data
base: dd 0
freep: dd 0
The code below gives this error:
:173: error: invalid combination of opcode and operands
So my question is how to a mov values into global variables?
mov freep, esi
回答1:
From the NASM manual:
2.2.2 NASM Requires Square Brackets For Memory References
The rule is simply that any access to the contents of a memory location requires square brackets around the address, and any access to the address of a variable doesn't.
So if you want to store the value of esi
at freep
you should write:
mov [freep], esi
And if you wanted to get freep
's address and put it in esi
you would've written:
mov esi, freep
The instruction mov freep, esi
is invalid, because freep
here is an immediate (the address of freep
), and you can't have an immediate as a destination operand.
来源:https://stackoverflow.com/questions/33341898/changing-global-variables-in-nasm-assembly