3

with this data

.data
tableD DWORD 10h, 20h, 30h, 40h, 50h, 60h
Rowsize = ($ - tableD)
DWORD 60h,70h,80h,90h,0A0h
DWORD 0B0h,0C0h,0D0h,0E0h,0F0h

I can use

.code
mov eax,tableD[ebx + esi*TYPE tableD]

but I can't use

mov eax,tableD[ebx*2 + esi*TYPE tableD]

but I can use

mov eax,tableD[ebx*2 + esi]

can't I use 2 *s in there?

can I know the terms for those objects?

Mysticial
  • 464,885
  • 45
  • 335
  • 332
  • 3
    This confusion wouldn't have happened with AT&T syntax. – fuz Jun 14 '17 at 19:08
  • 3
    @fuz yeah, but then the confusion arises, why there even some multiplication happens, and why that number inside parentheses doesn't add to the others... (you can't win this, you simply have to learn addressing modes, assembler will not hold your hand over basics... nor over advanced stuff... never) – Ped7g Jun 14 '17 at 20:07
  • @Ped7g In AT&T, it is 100% what addressing mode is used. Not so much in the strange Intel syntax which tries to make addressing modes look like symbol arithmetic. – fuz Jun 14 '17 at 21:36
  • Yeah, those Intel people had no idea what they were doing when they designed…oh wait. – Cody Gray - on strike Jun 15 '17 at 11:10
  • 1
    Possible duplicate of [Referencing the contents of a memory location. (x86 addressing modes)](https://stackoverflow.com/questions/34058101/referencing-the-contents-of-a-memory-location-x86-addressing-modes) – Cody Gray - on strike Jun 15 '17 at 11:12

1 Answers1

6

The x86 architecture supports a four-part addressing mode of the following form:

base + index * scale + displacement

where all four parts can be absent (scale is 1 if absent). This means that there can be only one scaled component in a memory operand; so yes, you can only use one *.

Furthermore, scaling factors are limited to 1, 2, 4, or 8; other scaling factors cannot be encoded.

fuz
  • 88,405
  • 25
  • 200
  • 352
  • 3
    @unlimitedcoding: the scale can be only power of two, and only first of them, 1, 2, 4 and 8. – Ped7g Jun 14 '17 at 20:09
  • @unlimitedcoding: See also [my broader answer about x86 addressing modes](https://stackoverflow.com/questions/34058101/referencing-the-contents-of-a-memory-location-x86-addressing-modes). This question could be closed as a duplicate of that (and Cody already voted to close as such), but my answer there is about 10x longer than this without giving much more information that directly answers this question :P – Peter Cordes Jun 28 '17 at 05:39
  • @unlimitedcoding and fuz: note that you can use more `*` operators *if* they can be evaluated at assemble time to produce a constant. e.g. `mov eax, [rdi*2 + TABLE_BASE + CONST_OFFSET*ENTRY_SIZE]`, where you defined those symbolic constants earlier with `equ` or `%define`. – Peter Cordes Jun 28 '17 at 05:42
  • @PeterCordes Which makes Intel syntax even less intuitive. – fuz Jun 28 '17 at 08:14
  • @fuz: I learned AT&T syntax first, and I remember liking the prefix decorators (`%` and `$`), and I think also the addressing-mode syntax. I like Intel syntax better than AT&T now, but I do remember finding it weird to see code with all kinds of stuff inside `[]`, and thinking it looked like a messy design that conflated addressing modes with assemble-time evaluation. – Peter Cordes Jun 28 '17 at 20:58