Search code examples
assemblyx86real-mode

Why is xor'ing DS not allowed?


I'm writing a program in real-mode x86 assembly and I'm trying to do this:

xor %ds, %ds

instead of the alternative:

mov $0, %ax
mov %ax, %ds

However, I'm getting an assembler error:

Error: operand type mismatch for `xor'

Why is this? Is there a way to get around this to decrease code size?


Solution

  • The encodings for the XOR instruction do not permit the segment registers as either the first or second operand. You may only use general purpose registers, memory locations, and immediate values.