Fix "NASM error: Invalid combination of opcode and operands" for add on Real Mode

Fix "NASM error: Invalid combination of opcode and operands" for add on Real Mode

我想在实模式下将 DS 寄存器增加 200h,但这样做时出现 "invalid combination of opcode" 错误:

add ds,200h

我用ax试了一下,没有问题。我猜这是因为 ds 自己注册了,但我对此没有任何解释。

我不是必须那样做,我通过这样做来修复它:

mov  ax,200h
mov  ds,ax 

但是我想知道具体的原因。谢谢你的时间。

add操作不能用于包括DS在内的段寄存器。不同之处在于 AX 是一个通用寄存器,因此一组不同的指令,包括 add 可用于该寄存器。

add ds,200h

I fixed it by doing this instead:

mov  ax,200h
mov  ds,ax 

该替换代码 不会将 DS 段寄存器提升 200h

正确的顺序是:

mov     ax, ds        ; Tranfer (copy) to a general purpose register
add     ax, 0200h     ; Do the arithmatic on that one
mov     ds, ax        ; Transfer the result back

DS这样直接处理段寄存器的唯一指令是:

push    ds
pop     ds
mov     ds, register/memory     e.g. mov ds, dx
mov     register/memory, ds     e.g. mov [bp+2], ds
lds     register, memory        e.g. lds si, [bx]