What Are the Different Addressing Modes Used in Assembly Language?

In summary: R8B is the lower 8 bits of R8, R8W is the lower 16 bits, R8D is the lower 32 bits, and just R8 is the 64 bit version.The LEA instruction allows you to load the memory at the address specified by the EAX register into the register EBX.There is an implied order to the instructions, with the leftmost operand being the first operand. So MOV EAX,4[EDI] is the same as MOV EAX,[EDI+4].Indirect addressing is when you use [] on the predefined addresses like EAX.If you want to load the value at location [EAX+DI]
  • #1
twoski
181
2

Homework Statement



I have a homework question: Calculate the effective address and determine the addressing mode that is specified for each memory operand in the following statements.

(a) MOV EAX, [label1] ; label1 is at location 0x00D5A360
(b) MOV EAX, [EBX] ; EBX points to location 0x00D5A360
(c) MOV EAX, label1[EDI] ;label1 is at location 0x00D5A360, DI is equal to 8
(d) MOV EAX, [EBP + ESI*4] ;EBP points to location 0x00D5A360, ESI is equal to 4
(e) MOV EAX, [EBX+100h] ;EBX points to location 0x00D5A360

The Attempt at a Solution



First of all, i am confused as to why assembly uses these addresses with arbitrary names. Why do EAX, EBX, etc. exist? My professor is terrible at explaining these things and his slides for lectures are cryptic.

Secondly, i cannot find a website that sufficiently explains the differences between direct/immediate/direct register/indirect register/base/base indexed/simple addressing. I don't know how to calculate effective addresses either and i can't find anything in the lecture slides about it.

My guesses for these:

  • Direct addressing is when you use [] to denote the data stored in a location.
  • Indirect is the opposite, you do not use [] and you access a location rather than data. (I don't get how this is any different though. if i did MOV X,Y and MOV X,[Y] where Y = 3 wouldn't it do the same thing?)
  • Register addressing looks to me like it's the exact same as indirect addressing, at least from the examples our teacher gave. Maybe it only uses the arbitrary predefined addresses?
  • Register indirect addressing is when you use [] on the predefined addresses like EAX.
  • Base addressing is like indirect addressing except you add a displacement to your base address (why would anyone do this?! wouldn't you be accessing data from some place that you don't want to?!)
  • Indexed addressing is when you access an array address(?)
  • Base indexed is like a combination of indexed and base addressing. Again, i don't see the use in it.

Anyhoo, back to solving it.

MOV EAX, [label1] makes no sense to me since [label1] results in the data stored at label1. But the question doesn't specify what is stored there, it just gives the address. I am guessing that using [] on a label results in its location. So if i have this hexadecimal number as my result, how do i figure out the effective address? Is that all i need?

I can't make much headway without knowing a lot of this stuff. It's just frustrating because i can't find any concrete definitions of anything.
 
Physics news on Phys.org
  • #2
Basic addressing allows you to load and store a single piece of data

Indexed addressing is used for working with a one dimensional array of data with the labeled address being element 0 of the array.

For 2D and above arrays then some calculation of an index is required as multi dimensioned arrays are flattened into a one dimensional structure.
 
  • #3
twoski said:
Why do EAX, EBX, etc. exist?
EAX, EBX are the names of the registers as 32 bit registers on a X86 processor. AX, BX, ... are the names for 16 bit registers, while RAX, RBX, are the names for 64 bit registers. In 64 bit mode, there are 8 additional registers with names like R8, R9, ..., R15, where a suffix is used, R8B is the lower 8 bits of R8, R8W is the lower 16 bits, R8D is the lower 32 bits, and just R8 is the 64 bit version.

twoski said:
Secondly, i cannot find a website that sufficiently explains the differences between direct/immediate/direct register/indirect register/base/base indexed/simple addressing. I don't know how to calculate effective addresses either and i can't find anything in the lecture slides about it.
Do a web search for "x86 addressing modes" or something similar:

Wiki article:

wiki_x86_adressing_modes

twoski said:
Direct addressing is when you use [] to denote the data stored in a location.
For some assemblers (Microsoft) [ ... ] is ignored by the assembler. If the value inside [ ... ] is a register or label reference to some location in memory, it's an address. If the value is an immediate value, without a segment prefix, it's an immediate value: MOV EAX, [01234h] is the same as MOV EAX, 01234h (just moves the value 01234h into EAX). If you want to move the contents of memory at location 01234h into EAX, you could use MOV EAX, DS:[01234h]. There isn't any implied order either, so MOV EAX,4[EDI] is the same as MOV EAX,[EDI+4].

LEA is a special instruction that loads the address into a register instead of the contents of memory at that address. So LEA EAX,[EBX*4] is the same as the two instruction sequence, MOV EAX,EBX ... SHL EAX,2.
 
Last edited:
  • #4
rcgldr said:
EAX, EBX are the names of the registers as 32 bit registers on a X86 processor. AX, BX, ... are the names for 16 bit registers, while RAX, RBX, are the names for 64 bit registers. In 64 bit mode, there are 8 additional registers with names like R8, R9, ..., R15, where a suffix is used, R8B is the lower 8 bits of R8, R8W is the lower 16 bits, R8D is the lower 32 bits, and just R8 is the 64 bit version.

I guess what's confusing me is why exactly we need to use these registers. Can't we just specify our own registers in .data?

Do a web search for "x86 addressing modes" or something similar:

Wiki article:

wiki_x86_adressing_modes

I don't find the wikipedia article to be all that helpful. What does a matrix full of arbitrary letters tell me about addressing modes? What do the letters in the first {}'s even represent?

For some assemblers (Microsoft) [ ... ] is ignored by the assembler. If the value inside [ ... ] is a register or label reference to some location in memory, it's an address. If the value is an immediate value, without a segment prefix, it's an immediate value

Ah, so the answer to the first one would simply be the address since [label1] gives us its address. What I'm worried about is that there's some sort of trickery to the question - do i need to do any additional math with that address to get the effective address?
 
  • #5
twoski said:
I guess what's confusing me is why exactly we need to use these registers. Can't we just specify our own registers in .data?

The registers are what are connected directly to the Arithmetic/Logic Unit. Think of them as the parameters provided to the internal hardware. They are faster to access than external memory. You set them with values of the outside world and then perform the operations on them. They also receive the results to be stored externally later.

In a way, they are the I/O ports for the ALU.
 
  • #6
Oh, this is starting to make much more sense now.
 
  • #7
twoski said:
Oh, this is starting to make much more sense now.

If you move from one cpu architecture to another the differences you will see regarding registers are the number of registers, width of the registers, bit level access, byte level access, word access, some of them will be dedicated to certain operations (hardwired to certain ALU functions), etc. SOme have completely general purpose registers whereby any can be specified as parameters for operations and any can receive the result, other only certain registers receive results .. others only use certain ones for multiplications and on and on. Some microcontroller architectures even map them to memory addresses. Some don't have a proper random access register file at all but only a stack that operand are pushed onto and results popped off of. It can get confusing, but in the end they are just latches inside the cpu that provide bits to the ALU and place that the ALU to store the results.
 
  • #8
Our professor never bothered explaining to us how you find the effective address with each addressing method, thankfully Wikipedia explains it well. These questions are a breeze!

Thank you all for the help.
 
Last edited:
  • #9
The naming conventions used by Intel are different than what you mentioned (direct, indirect, ...). The three operand types are immediate, register, or memory. In the case of memory, the standard addressing modes are: displacement, base + displacement, index * scale + displacement, base + index + displacement, base + index * scale + displacement.
 

Related to What Are the Different Addressing Modes Used in Assembly Language?

What is assembly?

Assembly is a low-level programming language that is used to write computer programs. It is also known as machine code or assembly language.

How is assembly different from other programming languages?

Assembly is considered a low-level language because it directly communicates with the computer's hardware, making it faster and more efficient than other programming languages. It also requires a deeper understanding of computer architecture and has a more complex syntax.

What is addressing in assembly?

Addressing in assembly refers to the process of specifying the location of data or instructions in memory. This is necessary for the computer to access and manipulate the data or execute the instructions.

Why is addressing important in assembly?

Addressing is important in assembly because it allows the programmer to access and manipulate data and instructions in memory, which is crucial for the functioning of a computer program. It also plays a role in optimizing program efficiency and memory usage.

How do I address data in assembly?

Data can be addressed in assembly using various addressing modes, such as direct, indirect, indexed, and relative addressing. The specific mode used will depend on the type of data and the desired operation.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
23
Views
5K
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top