3

I have searched for Addressing modes in IA-32,but I haven't seen any website or an article which have explained the addressing modes simply. I need an article or something which explain the matter simply by some picture of the memory during it changes and specifying the address mode by pictures.

I know that in IA-32 general form of addressing follows the following form :

Segment + Base + (index * scale) + displacement

I want to know the exact meaning of the displacement,scale,index and finally the base. As I don't know English as well I forced to search them but I didn’t find the technical mean of the words for this case ( In assembly programming language I mean ).

Finally, I want an explanation of addressing modes in IA-32 simply and preferably have been represented by pictures about The memory and its offset and ...

I learn assembly programming language by A guide to assembly programming in Linux's book.

So thanks.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user3679015
  • 61
  • 1
  • 7
  • See the _Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture, section 3.7.5 Specifying an Offset_. – Jester Aug 29 '14 at 12:17
  • As far as I know, there are about 30 different types of adressing modes possible, if all combinations are used. Chapter 4 of this link will clarify them all for You: http://www.ic.unicamp.br/~pannain/mc404/aulas/pdfs/Art%20Of%20Intel%20x86%20Assembly.pdf – icbytes Aug 29 '14 at 12:19
  • So Thanks to your reply.I'll read the pdf.I hope it clarifies the matter well. – user3679015 Aug 29 '14 at 12:25
  • Wikipedia shows all x86 addressing modes clearly: http://en.wikipedia.org/wiki/X86#Addressing_modes – nrz Aug 29 '14 at 15:19

1 Answers1

3

Found this image from this power point presentation.

Addressing modes

This means that you can have addresses like [eax + ecx * 2 + 100]. You don't necessarily have to use all of these fields.

See also Referencing the contents of a memory location. (x86 addressing modes)

The scale factor is encoded into machine code as a 2-bit shift count. ESP can't be an index because of special cases for indicating the presence of a SIB byte and for a SIB byte with no index. See rbp not allowed as SIB base? for a rundown on the special cases.


Segmentation can be ignored in 32/64-bit mode under normal OSes like Linux.

The segment register is selected automatically depending on the base register in the addressing mode, or with segment override prefix (e.g. ds:, cs:).

But Linux uses a flat memory model so the segment base is always 0 for all segments (other than fs or gs, used for thread-local storage). The segment base is added to the "offset" calculated from base, index, scale and displacement to get the final linear address. So normally the "offset" part is the whole linear address.

That linear address is a virtual address, which the hardware translates to physical via the page tables / TLB (managed by the kernel).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Mika Lammi
  • 1,278
  • 9
  • 21
  • The rest may be OK, but in the usual 32-bit addressing modes, segment registers are not "shifted left 4 bits and added to the address", they are usually indexes (indices) into a selector table. The selector has information about the segment. – Rudy Velthuis Aug 29 '14 at 15:04
  • To clarify, the 4-bit shifting only occurs in real mode. – Drew McGowen Aug 29 '14 at 15:12
  • So thanks for your reply cause it's simple and i got it.specially about shifting 4 bit in real mode and protected mode . – user3679015 Aug 29 '14 at 16:13
  • But I have another question about the picture.Why ESP can't use as index? and why the scale's numbers are just 1,2,4,8 ? why not 16,32 ? and the last question is what is the displacement word meaning in the assembly language programming ? I found another meaning about that in some dictionaries. So Thanks – user3679015 Aug 29 '14 at 16:19
  • 2
    @user3679015 See Intel or AMD manuals. There are no such addressing forms. SIB byte has only 2 bits for scale, therefore only 4 different scales are possible: 0b00: 1, 0b01: 2, 0b10: 4, 0b11: 8. ESP can't be used as index because there is no such encoding, as one of the encodings is used to encode a SIB without an index register. – nrz Aug 29 '14 at 20:46