16-bit Assembly: cannot deref some registers

核能气质少年 提交于 2019-12-13 10:36:39

问题


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?


回答1:


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, e.g. [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.



来源:https://stackoverflow.com/questions/52740507/16-bit-assembly-cannot-deref-some-registers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!