C memory segmentation

I am reading some C language text at url https://cs.senecac.on.ca/~btp100/pages/content/compu.html . The section "Segmentation" says: "One of the logical methods for managing the addressing of a large number of bytes is segmentation. Segmentation distinguishes certain areas of memory from other regions. For example, the operating system stores information about the program in selected segments." enter image description here

I do not quite understand.

For example, if I have the following program:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int x = 4;
    int y = 5;
    printf("%d\n", x+y);
  system("PAUSE");  
  return 0;
}

So, what is stored in Segment code, what is in Segment Data and what is in Stack? You are welcome.

Thank you so much

+5
source share
3 answers

- ( x y). . , , (, PAUSE).

+4

. , segmenation, x y SS, "% d\n" "PAUSE" DS CS.

+2

. , , 32- Windows, , 16- , .

When using a 32-bit type pointer, 32-bit systems can access the full virtual address space; therefore fs, Windows contains the key to special structures, such as TEB and PEB. However, in a strict sense with a flat memory model, there is no need for register segments.

Examples (for Windows, 32 bit):

mov eax, dword ptr fs:[18h] ; pointer to TEB
mov eax, dword ptr fs:[30h] ; pointer to PEB

In many modern systems cs, dsthey will refer, for example, to the same area.

0
source

All Articles