I am reading some text about the C language at the url https://cs.senecac.on.ca/~btp100/pages/content/compu.html. In the section "Segmentation", it says: "One logical technique for managing the addressing of a large number of bytes is segmentation. Segmentation distinguishes certain regions of memory from other regions. For example, an operating system stores program information in dedicated segments. "
I do not quite get it.
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 in Segment Data, and what in Stack? Please.
Thanks a lot
The stack is your local variables (such as x and y). The code segment is for the binary code that is actually executed. Finally, the data segment is for values that your program uses (such as the PAUSE string there).
This is compiler dependent. but in general, and assuming you have an OS that actually uses segmenation, your local variables x
and y
are referenced to SS, your string literals "%d\n" and "PAUSE" are referenced to DS and your actual assembled code is reference to CS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With