0
votes

I’m currently reading "Assembly Language step by step" by Jeff Duntemann. I’m somewhat frustrated by picture describing memory organization for protected flat model. It shows a piece of memory of 4GB size. There, instructions area is close to bottom ( low addresses), then data area above, and stack near the top. A the same time, if I understood it right, DS & CS registers in flat mode don’t affect start address of instructions or data (within those 4GB).

My question is:

who, then, distributes code and data areas (code below, data above), in those 4GB? Who decides at which address the instructions start and at which address data starts? There are some assembly programs in the book, but looks like programmer doesn’t choose memory location for instructions & data (within his ‘own’ 4GB). He just declares data section somewhere and types in the instructions. On the other hand, *.lst file already has addresses for instructions and data chunks. So is it Assembler that makes decision on addresses?

1
"Who decides at which address the instructions start": The operating system makes those decisions since it's the OS which knows how everything is already organised and which memory locations are available when the exe loads upady
Thanks Ady. But... Assembler listing file can actually show instructions and data addresses (relative to program's "own" 4GB ), prior to program being actually executed. I don't doubt that OS knows where in physical memory to place those 4GB chunk, even can split it into pieces, not visible by code writer. But I'm asking about addresses, or, if you want, offset inside this 4GB region - code at the bottom, data above, then stack at top. Looks like it is defined before OS knows anything about the program.Bob

1 Answers

0
votes

It is actually the linker that decides where the code and data sections. It varies from different linkers as to what the defaults are, but a lot of times they allow you to specify your own addresses (for example, ld linker scripts). This however, is only useful in a handful of situations, so you're better off just letting the linker pick the addresses on its own.