20

I'm new to assembly (as you can plainly see) and I'm trying to compile the following:

hex_charmap db '0123456789ABCDE'
mov   al, [hex_charmap + ax]

However I get the following error on line 2:

error: invalid effective address

What does this mean and how can I fix it?

Justin
  • 84,773
  • 49
  • 224
  • 367

1 Answers1

30

My assembler's rusty. Can AX really be used as an indexing register?

Update:

Just found what I was looking for. Only BX can be used as an index register!

See this link for another similar questions and its similar explanation:

invalid effective address calculation

Community
  • 1
  • 1
Carl Smotricz
  • 66,391
  • 18
  • 125
  • 167
  • Why is it that only `BX` can be used as an index register? – Sam Holmes Jan 14 '18 at 21:33
  • 1
    Essentially, that's how Intel designed their instruction set. Making all the registers equally all-round would have required more circuitry, brought up cost, making the chip slower and less efficient, and so forth. Other processors were designed differently, but not this one. – Carl Smotricz Jan 19 '18 at 13:12
  • @SamHolmes: Encoding limitations. But SI or DI can also be used in addressing modes, not just BX or BP. See the linked duplicate: [Differences between general purpose registers in 8086: \[bx\] works, \[cx\] doesn't?](https://stackoverflow.com/q/53866854) – Peter Cordes Oct 24 '22 at 10:53