when i initialize a segment register like this

mov ax,data
mov ds,ax

neighter the assembler nor the linker knows where the exe will be allocated in the memory.

the code ' mov ax,data ' looks like this in the debugger

B8C01C  (assuming data = 1CC0)

but in a hex editor you can see how it is assembled:

B80000  (mov ax,0)

So the (useless) questions are:
1. How does the OS modify the exe before running and makes the B8000 to B8C01C.
How does it know with mov ax,0 i meant mov ax,data. I could refer to data anywhere in the code for so many times.
2. Why is it so important for the OS to have such a function


To be honest; i'm asking this only for "academic" reasons, on programs running without OS i came around it with different solutions.
Bud it can be rigth to be answered before other OS Quichotte's hit it
Posted on 2005-12-09 13:19:57 by Confusius
I assume you're talking about 16bit DOS MZ .exe files?

It has a relocation table with addresses that need to be fixed up by the exe loader... check out wotsit.org or similar and find the MZ format reference.
Posted on 2005-12-09 14:48:57 by f0dder