- text segment - this contains the machine language
instructions for your program, depending upon the header
information this segment may be read only
- data segment - this segment contains the global
variables for your program, plus any memory that is
allocated dynamically while your program is executing
- stack segment - this segment contains the local
variables for the procedures in your program, each time a
procedure is called this segment could grow
-
Both the data (heap) and stack segment can grow while the
program is executing, the stack starts at the highest
memory address and the data segment starts just after the
text segment, they grow towards each other
-
What happens when our program starts executing?
-
Control is first transferred to the startup code that is
provided by the C compiler and operating system - this
code sets up the environment that the program runs in
-
In the UNIX environment the startup code first points
the stack pointer to the top of the memory space and then
prepares to call the main() procedure in your program
-
The main procedure should have the following
declaration:
|
|