Professional Documents
Culture Documents
CS 354 - Machine Organization Friday, September 23, 2016: Homework hw2 (1.5%) Due 10 PM Tuesday, September 27th
CS 354 - Machine Organization Friday, September 23, 2016: Homework hw2 (1.5%) Due 10 PM Tuesday, September 27th
CS 354 - Machine Organization Friday, September 23, 2016: Homework hw2 (1.5%) Due 10 PM Tuesday, September 27th
Last Time
Pointers to structs
Strings and string.h.
Standard & String I/O and stdio.h
Today
File I/O and stdio.h (from last time)
Where Do I Live?
C Memory Model
Address Space Layout
Next Time
Read: B&O 9.9.3 - 9.9.4
Dynamic Memory
CS 354 (F16): L8 - 1
Where do I live?
#include <stdio.h>
#include <stdlib.h>
int gus = 14;
int guy;
int madison(int pam) {
static int max = 0;
int meg[] = {22,44,88};
int *mel = &pam;
max = gus--;
return max + meg[1] + *mel;
}
int *austin(int *pat){
static int amy = 33;
int *ari = malloc(sizeof(int)*44);
gus--;
*ari = *pat;
return ari;
}
int main(int argc, char *argv[]) {
int vic = {33,66,99};
int *wes = malloc(sizeof(int));
*wes = 55;
guy = 66;
free(wes);
wes = vic;
wes[1] = madison(guy);
wes = austin(&gus);
free(wes);
printf("Where do I live?");
return 0;
}
CS 354 (F16): L8 - 2
C Memory Model
1. Text Segment (AKA Code Segment)
Contains: programs executable instructions from its object file
4. Heap
Memory allocation requested during execution.
Lifetime:
Contains:
Stack Frame:
CS 354 (F16): L8 - 3
32-bit Processor
11111111111111111111111111111111
OS Kernal
32-bit addresses:
0xC0000000/0x80000000
11111110110010010101001000010000
0xFEC95210
each address accesses 1 byte
max addressable bytes:
232 = 4,294,967,296 = 4GB
5. Stack
Unused
4. Heap
3. Uninitialized Data
bss
2. Initialized Data
data
1. Program Code
text
0x08048000
00001000000001001000000000000000
OS/C
Libraries/Misc
0x00000000
00000000000000000000000000000000
CS 354 (F16): L8 - 4