Commit c4725a6c authored by bbguimaraes's avatar bbguimaraes
Browse files


parent 9b9538af
\section{Euclidean algorithm}
\section{Machine language}
There are no "functions" per se in machine language\footnotemark. Control flow
happens with \textit{jump} instructions, including the equivalent of a function
call. The beginning of the call (equivalent to the initial expression followed
by parentheses, \texttt{f(…)}) can be a simple, unconditional jump. The
destination address is either a fixed value, as determined by the linker either
at link- or runtime for static or dynamic linking, or a dynamic value (i.e. from
a register) in the case of an indirect call. The end of the call (equivalent to
the \texttt{return} expression), conversely, is variable: it has to return to
the original place, right after the previous jump instruction.
Regardless, this section will use terms such as "call" and "return" for
simplicity of description.}
This is done via a region of memory called the \textit{stack}. It contains
different types of data about the runtime execution of the program, as will be
described in this section, but the one which is immediately interesting is the
\textit{return address}. Using the stack, the protocol for jumping to a new
code location and then back is:
Before the switch to the new location in code, the return address is
pushed onto the stack. This is the address of the next instructions
after the imminent jump.
When the target code is done and wishes to return to the previous
location, it pops the return value from the stack and jumps to it.
This process can be arbitrarily nested: the stack maintains the sequence of
return addresses required to return to the previous location at each level,
limited only by the total size of the stack\footnotemark.
\footnotetext{Limited roughly by the total size of memory, or a multiple of it.}
The region of memory where the stack is located is a closed range
denoted by two registers\footnotemark:
Implementation details in this section all use the x86 architecture as an
example, but these concepts are universal and most other architectures have
very similar concepts.}
is the \textit{base pointer}, the starting location of the stack.
is the \textit{stack pointer}, the location of the last element.
increments the pointer and writes a value to its location, equivalent
to (where \texttt{x} is a 32-bit register/value):
add rsp, 4
mov [rsp], x
reads the value pointed to by the pointer and decrements the pointer,
equivalent to (where \texttt{x} is a 32-bit register):
mov x, [rsp]
sub rsp, 4
......@@ -137,3 +137,17 @@ join(x, y)
// str(x ## y)
// "x ## y"
\subsection{Macro metaprogramming}
#define PROMOTE(x) (+(x))
#define PROMOTE_TO(x, y) (1 ? (x) : (y))
#define IS_SIGNED(x) (PROMOTE(-1, x) < PROMOTE(1, x))
......@@ -4,6 +4,7 @@
......@@ -15,6 +16,7 @@
......@@ -95,6 +95,10 @@ same order as $n$ --- i.e. $\Theta(n)$ --- or, more speecifically, at least of
the same order as $n$ --- i.e. $\Omega(n)$ --- this means the length of each
chain is $O(1)$.
% TODO gcc hashtab
% TODO;a=blob;f=include/hashtab.h;hb=HEAD
% TODO;a=blob;f=libiberty/hashtab.c;hb=HEAD
struct entry { u32 /*h,*/ k, v; };
......@@ -240,8 +240,12 @@ for(struct node *n = l; prefetch(n->next), n; n = n->next)
// ...
% TODO review
\subsection{Doubly linked list}
% TODO doubly linked
\section{Reference counting}
% TODO reference counting
\section{Binary tree}
% TODO binary tree
% TODO nngn flag_array / bvh
\subsection{Red-black tree}
% TODO red-black tree
% TODO Linux kernel design patterns - part 2
% TODO Linux kernel design patterns - part 3
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment