From 0fc3af3f220e60e67aceb6c4739ab0f0cbfab79c Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Wed, 15 Oct 2014 12:21:46 +0200 Subject: [PATCH] lesson 12 --- 12-kernel-c/README.md | 13 ++++++++----- 12-kernel-c/functioncalls.c | 7 +++++++ 12-kernel-c/localvars.c | 4 ++++ 12-kernel-c/pointers.c | 3 +++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 12-kernel-c/functioncalls.c create mode 100644 12-kernel-c/localvars.c create mode 100644 12-kernel-c/pointers.c diff --git a/12-kernel-c/README.md b/12-kernel-c/README.md index f27c153..ebb9c5d 100644 --- a/12-kernel-c/README.md +++ b/12-kernel-c/README.md @@ -55,8 +55,11 @@ More I encourage you to write more small programs, which feature: -- Local variables -- Function calls -- Pointers - -Then compile and disassemble them, and examine the resulting machine code. +- Local variables `localvars.c` +- Function calls `functioncalls.c` +- Pointers `pointers.c` + +Then compile and disassemble them, and examine the resulting machine code. Follow +the os-guide.pdf for explanations. Try to answer this question: why does the +disassemblement of `pointers.c` not resemble what you would expect? Where is +the ASCII `0x48656c6c6f` for "Hello"? diff --git a/12-kernel-c/functioncalls.c b/12-kernel-c/functioncalls.c new file mode 100644 index 0000000..f53c84c --- /dev/null +++ b/12-kernel-c/functioncalls.c @@ -0,0 +1,7 @@ +void caller() { + my_func(0xdede); +} + +int my_func(int arg) { + return arg; +} diff --git a/12-kernel-c/localvars.c b/12-kernel-c/localvars.c new file mode 100644 index 0000000..90d5982 --- /dev/null +++ b/12-kernel-c/localvars.c @@ -0,0 +1,4 @@ +int my_function() { + int my_var = 0xbaba; + return my_var; +} diff --git a/12-kernel-c/pointers.c b/12-kernel-c/pointers.c new file mode 100644 index 0000000..f70054a --- /dev/null +++ b/12-kernel-c/pointers.c @@ -0,0 +1,3 @@ +void func() { + char* string = "Hello"; +}