1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  1. text segment - this contains the machine language
    instructions for your program, depending upon the header
    information this segment may be read only
  1. data segment - this segment contains the global
    variables for your program, plus any memory that is
    allocated dynamically while your program is executing
  1. 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


Program Execution

  • 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:

March 3, 1998

Page 9

C201/TAM