6

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
  • 328,167
  • 45
  • 605
  • 847
Michael
  • 892
  • 2
  • 10
  • 28
  • 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
  • Related: [8086 assembly register indirect MOV instruction](https://stackoverflow.com/q/56759424) and [Differences between general purpose registers in 8086: \[bx\] works, \[cx\] doesn't?](https://stackoverflow.com/q/53866854) are duplicates, different formatting of the table showing the valid options. – Peter Cordes Dec 13 '22 at 17:29

1 Answers1

16

[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
  • 328,167
  • 45
  • 605
  • 847
Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
  • 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