Adding Ch3 code
parent
43fa9f4e80
commit
f591dc02a3
@ -1,2 +1,4 @@
|
||||
# think_os
|
||||
# Think OS
|
||||
|
||||
Repo following the [Think OS](http://greenteapress.com/thinkos/) book.
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
.PHONEY: build object_code optimal assembly preprocess clean
|
||||
|
||||
build:
|
||||
gcc hello.c -o hello
|
||||
|
||||
object_code:
|
||||
gcc hello.c -c
|
||||
|
||||
optimal:
|
||||
gcc hello.c -O1 -o hello_optimal
|
||||
|
||||
assembly:
|
||||
gcc hello.c -S
|
||||
|
||||
preprocess:
|
||||
gcc hello.c -E
|
||||
|
||||
clean:
|
||||
rm -rf hello hello_optimal hello.o hello.s
|
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
printf("Hello dirp\n");
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
.PHONY: build all
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
gcc aspace.c -o aspace
|
||||
|
||||
clean:
|
||||
rm -rf aspace *.o *.s
|
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// code segment - program text
|
||||
// constant segment - immutable values. *s for example.
|
||||
// globals - global variables or local variables marked 'static'
|
||||
// heap - memory allocated at runtime. Grows towards the top virtual address space
|
||||
// stack - sequence of stack frames. Grows from the top of the virtual-address space
|
||||
|
||||
int global;
|
||||
|
||||
int main(){
|
||||
int local = 5;
|
||||
void *p = malloc(128);
|
||||
char *s = "Hello, World";
|
||||
|
||||
printf("Address of main is %p\n", main);
|
||||
printf("s points to %p\n", s);
|
||||
printf("Address of global is %p\n", &global);
|
||||
printf("Address of local is %p\n", &local);
|
||||
printf("p points to %p\n", p);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue