L f2x 10 return f2x void f1int x1 int x2 float x3 char x4 double x5 int x6 int

L f2x 10 return f2x void f1int x1 int x2 float x3

This preview shows page 6 - 9 out of 14 pages.

L: f2_x = 10; return f2_x; } void f1(int x1, int x2, float x3, char x4, double x5, int x6) { int f1_x = 10; int f1_y; char *f1_p1 = "This is inside f1"; // pointer to another string literal char *f1_p2; f1_p2 = malloc(100); // dynamically allocated memory / print out the addresses of x1, x2, x3, x4, x5, x6 / print out the addresses of f1_x, f1_y, f1_p1, f1_p2 / print out the address of the string literal "This is inside f1" ..... f1_y = f2(10); return; } int main(int argc, char *argv[]) { printf("My OS bit size: %lu\n", sizeof(void *) * 8); / print out the addresses of argc, argv / print out the starting address and ending address of the command line arguments of this process / print out the starting address and ending address of the environment of this process (values and variables. / print out the starting addresses of function main, f1, and f2 / print out the addresses of global_x, global_y, global_array1, global_array2, global_pointer1, / global_pointer2, global_float, global_double / print out the addresses of string literals "Hello, world!" and "bye!" ..... // call function f1 with suitable arguments such as 12, -5, 33.7, 'A', 1.896e-10, 100 f1( .... );
Image of page 6
Image of page 7
exit(0); } The following example shows how to use the function addr to display the address, e.g. int x; char *p="this is a string literal"; printf("address of x is at %s\n", addr((unsigned long) &x)); printf("address of p is at %s\n", addr((unsigned long) &p)); printf("address of the string literal is at %s\n", addr((unsigned long) p)); Alternatively, you can display the virtual addresses in hexadecimal notation, e.g.: int x; char *p="this is a string literal"; printf("address of x is at %p\n", &x)); printf("address of p is at %p\n", &p)); printf("address of the string literal is at %p\n", p); 2. (14 marks) Based on the information generated from the above program, produce a memory map table showing the layout of literals, initialised global variables, uninitialised global variables, formal parameters of each function, local variables, dynamically allocated variables, functions, environment and command line arguments in the memory when the program reaches label L in function f2 . The memory map table must show the addresses of each variable, literal, and function and their sizes . It should also show the start and end addresses of the environment and the command line arguments and their sizes . The memory map table must contain at least the following columns : a. The start address of an entity such as a variable or a function b. The length of the storage space of the entity in bytes c. The name of the entity, such as global_pointer1 or Hello, world! d. The nature of the entity, such as function , or uninitialsed global variable e. The memory section (see below) In addition, you must use seven different background colours to highlight the following seven memory sections : initialised global variables (including constants and literals) uninitialised global variables stack (containing the local variables and returning addresses of function calls) heap (containing the dynamically allocated memories) code (functions) process environment command command line args Please also note that each of the above seven memory sections are laid out contiguously in one block of memory. If you find that components of one section are split up into more than one contiguous area of memory, it is a sure indication that there is something wrong with your memory map and you should find out what went wrong and fix it.
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 14 pages?

  • Winter '18
  • Mandy
  • Virtual memory, Central processing unit, Global variable

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture