NASM x86 16-bit addressing modes [duplicate]
Asked Answered
A

1

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?

Alleluia answered 18/9, 2012 at 9:21 Comment(2)
Related: Why don't x86 16-bit addressing modes have a scale factor, while the 32-bit version has it? explains why 16-bit addressing modes are more limited.Caia
Related: 8086 assembly register indirect MOV instruction and Differences between general purpose registers in 8086: [bx] works, [cx] doesn't? are duplicates, different formatting of the table showing the valid options.Caia
T
17

[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.

Tiler answered 18/9, 2012 at 9:32 Comment(2)
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.Osmious
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/16Caia

© 2022 - 2024 — McMap. All rights reserved.