What do ds:si and es:di mean in assembly?
Asked Answered
S

2

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?

Sokil answered 1/11, 2011 at 1:27 Comment(2)
A good read: en.wikipedia.org/wiki/…Spikenard
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. en.wikipedia.org/wiki/Segment_registerPolyester
N
15

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.

Nocuous answered 1/11, 2011 at 1:30 Comment(6)
Do you mean we don't need to specify the value of ds and es manually?Sokil
@new_perl: No, not on almost anything reasonably current anyway.Nocuous
Then who manipulates the segment registers?Does segment * 16 + offset point to the physical memory address?Sokil
@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.Nocuous
Is it true that the OS works in real mode,but user applications work in protected mode?Sokil
@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).Nocuous
F
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

Fernandez answered 14/7, 2019 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.