For 8086 it is possible to override the segment of the source index SI in order to use ES instead of DS. In a book (the old Scanlon) I found:
LEA SI,ES:HERE
LEA DI,ES:THERE
MOVSB
As LEA retrieves just the OFFSET of a memory address (16 bits for the 8086), how MOVSB knows that SI refers to the ES segment and not the DS segment? Is LEA changing the default segment for SI? I have not read anything about that in the many pages and manuals I found.
CodePudding user response:
That code looks wrong. Without a segment override prefix, movsb will use DS:SI and ES:DI always. Unless you have to worry about errata of ancient processors you can make this code work by giving a segment override prefix to movsb. es:MOVSB will tell it to use ES:SI rather than DS:SI. movsb always copies to ES:DI; no segment override prefix will change it.
The code could actually be right if DS is guaranteed to equal ES at this location. The old assemblers had their own ides of things and sometimes funny segment overrides had to be used to keep the assembler happy.
CodePudding user response:
I have installed a MASM6.11 in a DOSBOX and did some experiments. Here is the memory map pf the data segments:
0000 dseg segment para public 'data'
0000 41 42 43 44 src db 'ABCD'
0004 dseg ends
0000 eseg segment para public 'data'
0000 5A 5A 5A 5A dummy db 'ZZZZ'
0004 31 32 33 34 dst db '1234'
0008 eseg ends
0000 cseg segment para public 'code'
assume cs:cseg, ds:dseg, es:eseg
The results are that the code:
LEA SI,ES:HERE
LEA DI,ES:THERE
MOVSB
is wrong: the segments are not considered at all, it copies from DS to ES in any case (OP-CODE is A4):
8D 36 0000 R
8D 3E 0004 R
A4
In order to achieve a copy from ES to ES you write:
LEA SI,ES:HERE
LEA DI,ES:THERE
MOVS ES:THERE, ES:HERE
which translates to:
8D 36 0000 R
8D 3E 0004 R
26: A4
Syntaxes ES MOVSB and ES:MOVSB I read in the answers do not work with MASM 6.11 (but they actually corresponds to what it is translated to: 26 is the code for ES).
