简体   繁体   中英

16-bit Assembly: cannot deref some registers

I'm trying the following Intel 16 bit instruction:

mov si, word [reg]

where reg is some register. It compiles fine if reg is bx , but does not when it is ax , cx or dx . I'm using NASM as my assembler. I'm sure this due to some restrictions in the instruction set. Can some one please explain the restriction and the rationale behind it?

Only the following index registers can be used with 16 bit addressing modes:

bx
si
di
bp
bx + si
bx + di
bp + si
bp + di

Likewise, SIB addressing is not available with 16 bit addressing modes.

If you want to use other index registers, you can always use a 32 bit addressing mode, eg [eax] . This works as long as you run your code on an 80386 or newer processor.

This restriction exists because the modr/m byte only has three bits for the (index) register. As you can see above, exactly 8 possible index register combinations exist. I don't know why they designed the addressing modes to be like that, but it sounds pretty reasonable for a 70's era 16 bit processor as the 8086 is.

In 32 bit mode and long mode, this scheme was changed so 7 of the 8 possible index registers refer to eax, ebx, ecx, edx, esi, edi, and ebp while what would refer to esp instead indicates the presence of a sib byte allowing for the well known [base+index*scale] addressing modes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM