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.
|
||||
|
||||
Reference in New Issue
Block a user