15

The movsb (move string, bytes) instruction fetches the byte at address ds:si, stores it at address es:di, and then increments or decrements the si and di registers by one.

I know esi,si and edi,di registers,

but not ds:si and es:di ,

what do they mean?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
new_perl
  • 7,345
  • 11
  • 42
  • 72
  • 1
    A good read: http://en.wikipedia.org/wiki/X86_assembly_language#Segmented_addressing – Ray Toal Nov 01 '11 at 01:28
  • 1
    If you want to know how 16-bit code used to work then you do have travel back into the previous century and understand segment registers. http://en.wikipedia.org/wiki/Segment_register – Hans Passant Nov 01 '11 at 01:33

2 Answers2

14

ds:si and es:di mean the segment:offset referred to by the registers in question. This is primarily important when you're working in real mode (where offsets are a maximum of 64K apiece).

In real mode, the segment and offset are combined as segment * 16 + offset.

In protected mode, a segment register holds a "selector". The base address of the memory referred to by the selector isn't directly related to the value of the selector itself -- rather, the selector just acts as an index to look up data in a table. In the usual case, however, this means very little -- most (current) protected mode environments are set up with CS, DS, ES and SS all set up with base addresses of 0 and maximum offsets of 4 Gigabytes, so addressing via DS vs. ES makes no difference.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • 1
    Do you mean we don't need to specify the value of `ds` and `es` manually? – new_perl Nov 01 '11 at 01:39
  • @new_perl: No, not on almost anything reasonably current anyway. – Jerry Coffin Nov 01 '11 at 01:41
  • Then who manipulates the segment registers?Does `segment * 16 + offset` point to the **physical** memory address? – new_perl Nov 01 '11 at 01:42
  • 1
    @new_perl: in real mode (where the segment*16+offset is used), yes. In protected mode, the selector in the segment register is used for a table lookup, and the base address is found in the table. – Jerry Coffin Nov 01 '11 at 01:45
  • Is it true that the OS works in real mode,but user applications work in protected mode? – new_perl Nov 01 '11 at 02:01
  • @new_perl: Not on a modern OS, no. The OS kernel runs in kernel mode, which is vaguely like real mode in having full access to all memory, but that's about it. On most current OSes, the segment registers simply don't get manipulated much -- the OS sets them up while booting, and they pretty much get left along after that (the sole obvious exception being FS under Windows, which always points to a thread data block). – Jerry Coffin Nov 01 '11 at 02:40
2

These are 16 bit registers, they are used for operations like LODSB or others that loop trough memory and either apply or copy data. You load an address into es:di or ds:si and set the cx to whatever count of bytes or words you need top copy and call the LODSB LOADSW or whatever. You can even copy from one memory location to another this way using both. See an example here where they copy a string to a serial port: http://vitaly_filatov.tripod.com/ng/asm/asm_000.71.html

nivs1978
  • 1,126
  • 14
  • 20