As the web-resources on this is sparse, I will, for the benefit of future searches, begin by listing the address modes for IA-32 Assembly Language (NASM) and then follow up with a quick question.
Please note that the above is for NASM. For MASM/TASM you'd use "mov esi, OFFSET foo" to get the address, while "mov esi, foo" and "mov esi, [foo]" both would get the value (creds to @Michael).
So, onto my question. It is in in relation to an example at the bottom of page 29 of the following tutorial: http://www.tutorialspoint.com/assembly_programming/assembly_tutorial.pdf
It basically lists the below code as an example of indirect memory addressing.
MY_TABLE TIMES 10 DW 0 ; Allocates 10 words (2 bytes) each initialized to 0
MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110
ADD EBX, 2 ; EBX = EBX +2
MOV [EBX], 123 ; MY_TABLE[1] = 123
My questions:
IA-32 (short for "Intel Architecture, 32-bit", sometimes also called i386) is the 32-bit version of the x86 instruction set architecture, designed by Intel and first implemented in the 80386 microprocessor in 1985.
It copies the data of 2nd operand (source) into the 1st operand (destination). To access memory, segment registers are used along with general-purpose registers. There are seven addressing modes in 8086 processor. Now, we will discuss all of them in detail with example assembly instructions.
In NASM syntax, that instruction should be MOV EBX, MY_TABLE
. What MOV EBX, [MY_TABLE]
would do is load the first 4 bytes located at MY_TABLE
into EBX
. Another alternative would be to use LEA
, as in LEA EBX, [MY_TABLE]
.
In this case the tutorial is right. MY_TABLE
is defined as an array of words. A word on the x86 is 2 bytes, so the second element of MY_TABLE
is indeed located at MY_TABLE + 2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With