I'm new to Assembly programming, and searched the web for tutorials and ebooks. I have found some confusing information about syntax in assembly language eg in a tutorial I read the following code:
MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110
And in a book I read:
mov ax, [Data] ; normal direct memory addressing of a wor
mov ebx, Data ; ebx = & Data
3 mov ax, [ebx] ; ax = *ebx
So when we MOV
a variable enclosed in []
to a register like EBX
, what value do we store in the register? The address or the actual value in that memory location?
From the NASM manual :
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 an instruction of the form
mov ax,foo
will always refer to a compile-time constant, whether it's anEQU
or the address of a variable; and to access the contents of the variablebar
, you must codemov ax,[bar]
.
So
MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
is wrong: It does not set EBX
to an address, but to the value stored at the MY_TABLE
address.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.