Adding Ch3 code

master
Drew Bednar 5 years ago
parent 43fa9f4e80
commit f591dc02a3

1
.gitignore vendored

@ -32,3 +32,4 @@
# Debug files
*.dSYM/
.idea/

@ -6,3 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -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…
Cancel
Save