00001 00002 /* segments.c 00003 * Simple program to illustrate different segments and to show 00004 * how parameters are passed and the syscall is generated. 00005 * 00006 * objdump below refers to: 00007 * /software/gcc_nachos/bin/decstation-ultrix-objdump 00008 * 00009 * Compile this "gmake segments" 00010 * Then use objdump to examine output. 00011 * objdump -d segments.coff - to disassemble 00012 * objdump -s segments.coff - to see contents of segments 00013 * objdump -x segments.coff - to see symbol table information 00014 * nachos -d m -s -x segments 00015 */ 00016 00017 #define N (5) /* N is replaced by the preprocessor */ 00018 00019 unsigned int initdata1 = 0xdeadbeef; /* initialized data put in .data segment */ 00020 int initdata2 = 0xbb; /* same as above */ 00021 const int blah = 0xff; /* into .rdata segment */ 00022 int uninitdata[N]; /* allocate space in .bss segment */ 00023 00024 main() 00025 { 00026 /* automatic variable stored on stack or in register */ 00027 int i; 00028 int stack1 = 0xaa; 00029 int stack2; 00030 const int stack3 = 0xee; /* in reg or on stack not .rdata */ 00031 char *str = "Hello World .rdata segment\n"; 00032 00033 /* str is stored on the stack or in a register 00034 * but text that is initialized is stored in .rdata 00035 */ 00036 00037 for (i=0; i<N; i++) { 00038 uninitdata[i] = i; 00039 } 00040 Halt(); 00041 }