5

I am having trouble with pointing to a address and write in my case a variable of byte in size. This gives me the error "error: invalid effective address":

mov byte[AX], byte 0x0

After some trail and error i tested the same but with EAX. This compiles just fine:

mov byte[EAX], byte 0x0

What am I missing here?

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Michael
  • 715
  • 2
  • 8
  • 21
  • Related: [Why don't x86 16-bit addressing modes have a scale factor, while the 32-bit version has it?](https://stackoverflow.com/q/55657904) explains why 16-bit addressing modes are more limited. – Peter Cordes Dec 01 '20 at 03:03

1 Answers1

14

[AX] is an invalid memory operand specification.

The valid 16-bit ones are:

[constant]  
[BX]  
[SI]  
[DI]  
[BX+constant]  
[BP+constant]  
[SI+constant]  
[DI+constant]  
[BX+SI]  
[BX+DI]  
[BP+SI]  
[BP+DI]  
[BX+SI+constant]  
[BX+DI+constant]  
[BP+SI+constant]  
[BP+DI+constant]  

[BP] is formally invalid, but many assemblers will quietly convert it into [BP+0].

See the CPU manual for memory operand encodings and the ModR/M and SIB bytes.

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Alexey Frunze
  • 59,618
  • 10
  • 77
  • 173
  • 9
    When using `[bp+constant]`, `[bp+si+constant]` or `[bp+di+constant]`, it's good to remember that the default segment for all these addressing modes with `bp` is `ss` (stack segment), not `ds` (data segment), as it is for all other addressing modes listed above. – nrz Sep 18 '12 at 11:15
  • 1
    Note that 16-bit addressing modes can't use a SIB byte, only ModR/M, which is why they're limited to `(BP|BX) + (DI|SI) + disp0/8/16` – Peter Cordes Nov 23 '17 at 10:32