What Are the Different Addressing Modes Used in Assembly Language?

  • Thread starter Thread starter twoski
  • Start date Start date
  • Tags Tags
    Assembly Confused
Click For Summary

Discussion Overview

The discussion revolves around the different addressing modes used in assembly language, specifically in the context of x86 architecture. Participants are exploring how to calculate effective addresses and identify the addressing modes for various assembly instructions.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant expresses confusion about the purpose of registers like EAX and EBX, questioning why they exist and how they differ from user-defined variables.
  • Another participant explains that EAX and EBX are 32-bit registers in x86 architecture, with variations for 16-bit and 64-bit registers.
  • There is a discussion about the differences between addressing modes, with some participants attempting to define direct, indirect, and register addressing, but expressing uncertainty about their distinctions.
  • One participant suggests that indexed addressing is used for one-dimensional arrays, while others mention the need for calculations in multi-dimensional arrays.
  • Some participants share their attempts to understand effective addresses and express frustration over the lack of clear definitions in their course materials.
  • A later reply discusses the use of brackets in assembly language to denote memory addresses, indicating that the interpretation can vary based on context.
  • Participants mention that the naming conventions for addressing modes may differ from what they have learned, with one noting that the standard operand types are immediate, register, or memory.

Areas of Agreement / Disagreement

Participants generally agree on the existence and basic function of registers but express differing views on the definitions and applications of various addressing modes. The discussion remains unresolved regarding the clarity and utility of these modes.

Contextual Notes

Participants note limitations in their understanding due to unclear lecture materials and varying definitions of addressing modes. There is also mention of potential confusion arising from different naming conventions in assembly language documentation.

twoski
Messages
177
Reaction score
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
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.
 
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:
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?
 
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.
 
Oh, this is starting to make much more sense now.
 
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.
 
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:
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 23 ·
Replies
23
Views
6K
  • · Replies 12 ·
Replies
12
Views
5K