Redundant DS segment override prefix inserted by nasm?

assembly, disassembly, nasm, x86

Solution

If you typed in `mov [ds:bx], eax` the assembler should assemble `mov [ds:bx], eax`. NASM is not (and should not!) an optimizing assembler which corrects your inputs. Maybe you exactly need space of four bytes for modifying the program code.

Problem

I am working on a x86 disassembler for educational purposes. I have been using nasm for assembling different instructions. Currently I am looking into the 16-bit addressing forms with the ModR/M byte. The "Intel 64 and IA-32 Architectures Software Developers Manual: Volume 2A Instruction Set Reference, A-M" (I think my version is outdated but this information should still hold true) states that "The default segment register is SS for the effective addresses containing a BP index, DS for other effective addresses". So if I understand this correctly, the following instructions should do exactly the same: ``` mov [bx], eax mov [ds:bx], eax ``` However, when I compile the above instructions using nasm and look at the bytes generated, I get the following: ``` 67 89 07 mov [bx], eax 3e 67 89 07 mov [ds:bx], eax ``` I understand the meaning of all the bytes, but I do not understand why nasm would add a ds segment override prefix (3e) to the second instruction. It seems unnecessary to me since ds already is the default segment. My question is: am I missing something here or is the ds segment override prefix not needed?

Original source