mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 17:00:05 +01:00
[SPCA] Fix various errors
This commit is contained in:
@@ -11,12 +11,13 @@ The following condition codes were covered in the lecture (operation: \texttt{t
|
||||
\content{Explicit computation}
|
||||
In the below explanations, we always assume \texttt{src2 = b} and \texttt{src1 = a}
|
||||
|
||||
To explicitly compute them, we can use the \texttt{cmpX src2, src1} instruction (with X again any of the size postfixes),
|
||||
To explicitly compute them, we can use the \texttt{cmpX src2, src1} (i.e. for easier understanding, \texttt{cmpX b, a}) instruction (with X again any of the size postfixes),
|
||||
that essentially computes $(a - b)$ without setting a destination register.
|
||||
|
||||
When we execute that instruction, \texttt{CF} is set if \texttt{a < b} (unsigned), \texttt{ZF} is set if \texttt{a == b}, \texttt{SF} is set if \texttt{a < b} (signed)
|
||||
and \texttt{OF} is set as above, where \texttt{t = a - b}.
|
||||
|
||||
Another instruction that is used is \texttt{testX src2, src1} (X again a size postfix), and acts like computing \texttt{a \& b} and where \texttt{ZF} is set if \texttt{a \& b == 0}
|
||||
Another instruction that is used is \texttt{testX src2, src1} (X again a size postfix, easier: \texttt{testX b, a}), and acts like computing \texttt{a \& b} and where \texttt{ZF} is set if \texttt{a \& b == 0}
|
||||
and \texttt{SF} is set if \texttt{a \& b < 0}.
|
||||
|
||||
\content{Zeroing register} We can use a move instruction, but that is less efficient than using \texttt{xorl reg, reg}, where \texttt{reg} is the 32-bit version of the reg we want to zero.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
\subsubsection{Jumping}
|
||||
To jump, use \texttt{jmp <label>} (unconditional jump) or the \texttt{jC} instructions, with \texttt{C} from table \ref{tab:condition-codes}
|
||||
To jump, use \texttt{jmp <label>} (unconditional jump) or the \texttt{jC <label>} instructions, with \texttt{C} from table \ref{tab:condition-codes}
|
||||
|
||||
\begin{table}[h!]
|
||||
\begin{tables}{lll}{\texttt{setX} & Condition & Description}
|
||||
\begin{tables}{lll}{\texttt{setC} & Condition & Description}
|
||||
\texttt{e} & \verb|ZF| & Equal / Zero \\
|
||||
\texttt{ne} & \verb+~ZF+ & Not Equal / Not Zero \\
|
||||
\texttt{s} & \verb|SF| & Negative \\
|
||||
@@ -23,11 +23,11 @@ To jump, use \texttt{jmp <label>} (unconditional jump) or the \texttt{jC} instru
|
||||
Similar to \texttt{jC}, the same postfixes can be applied to \texttt{cmovC}, for example:
|
||||
|
||||
\begin{minted}{gas}
|
||||
cmpl %eax, %edx
|
||||
cmovle %edx, %eax
|
||||
cmpl %eax, %edx # computes (edx - eax) without overwriting edx
|
||||
cmovle %edx, %eax # only copies edx into eax if edx <= eax
|
||||
\end{minted}
|
||||
|
||||
Will move \verb|%edx| into \verb|%eax|, only if \verb|%edx| is less or equal (\verb|le|) \verb|%eax|.
|
||||
Due to the computed condition flags, this will move \verb|%edx| into \verb|%eax|, only if \verb|%edx| is less than or equal (\verb|le|) to \verb|%eax|.
|
||||
|
||||
This can be used to, for example, compile ternary expressions from \verb|C| to Assembly.
|
||||
However, this requires evaluating both possible expressions, which may lead to a (significant) performance overhead.
|
||||
|
||||
@@ -32,7 +32,7 @@ The same function, using a \verb|while| loop instead may lead to this:
|
||||
\verb|for| loops follow the same idea as \verb|while| loops, albeit with a few more jumps.
|
||||
|
||||
\verb|switch| statements are implemented differently depending on size and case values:
|
||||
Sparse switch statements are compiled as decision trees, whereas large switch statements may become \textit{jump tables}.
|
||||
Sparse switch statements are compiled as decision trees, whereas compact switch statements may become \textit{jump tables}.
|
||||
|
||||
These jump tables are usually stored in the \texttt{.rodata} section with 8-byte alignment. The jump uses offsets:
|
||||
\mint{gas}|jmp *.LABEL(, %rsi, 8)|
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
\newpage
|
||||
\subsection{The Stack}
|
||||
\label{sec:asm-stack}
|
||||
The Stack is the main way to dynamically allocate memory in Assembly, i.e. for temporary values. This process is completely manual: Allocating/Deallocating memory on the stack is entirely explicit. The stack grows \textit{downwards}: Addresses decrease as the stack grows.
|
||||
The Stack pointer \verb|%rsp| points to the current top of the stack.
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ We can implement that either by rewriting the functions into a single function,
|
||||
A way around this is to use \bi{Continuations}, where the first function saves its state and the context is switched to the other function.
|
||||
That function can then load its state and continue where it left off, runs until it finishes its task, then saves its state and the context switches back to the original function.
|
||||
\inputcodewithfilename{c}{}{code-examples/01_asm/10_coroutine.h}
|
||||
\newpage
|
||||
\inputcodewithfilename{c}{}{code-examples/01_asm/10_coroutine.c}
|
||||
|
||||
As you can see, the \texttt{setjmp.h} functions are the foundation of all concurrent programming.
|
||||
|
||||
Reference in New Issue
Block a user