In my computer architecture class, we learned about registers (intel 8086 microprocessor) and were given exercises about determining the physical address from a line of assembly. Something like: MOV [SI], AX
All the register contents would be given to us. But I had a question: In a line like MOV [SI+BP], AX. What segment register would be used here? From reading the notes, my understanding was that by default, the DS is used, especially with SI being present. However since BP is also present, you would then use SS instead.
However when I asked my lecturer about it, she told me that my thinking was wrong, and that it in fact is DS because SI came first in the assembly code, so based on that, and the fact that SI is related to DS, we use DS.
I'm quite confused now, and she has a history of giving wrong answers to questions. So I'd like to double confirm here. If anyone could link to any official documents as well that would be much appreciated.
[SI+BP]
vs [BP+SI]
is only an assembly-level difference, there is only one way to encode them so there is no real distinction to be made. They cannot use different default segments because to the processor they are the same thing, the processor cannot know whether you wrote [SI+BP]
or [BP+SI]
at the assembly level.
Here's the 16-bit ModR/M table (different than the 32/64-bit table so be sure to look at the right one) from Intel's Software Developmer's Manual, found in chapter 2 of volume 2. In the notes below, the default segment is described as: "The default segment register is SS for the effective addresses containing a BP index, DS for other effective addresses". I don't know if "a BP index" is the best way to describe this, but it ends up meaning "any memory address with BP in it".
Alternatively this table is clearer about which memory addressing forms default to the SS segment (being indicated in the table instead of relegated to a note that needs to be interpreted by the reader), but it's a less authoritative source.