mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-01-12 20:28:31 +00:00
[SPCA] more assembly
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
\subsection{Operations}
|
||||
Assembly operations include performing arithmetic or logic functions on registers or memory data,
|
||||
transferring data between memory and registers and transferring control (conditional or unconditional jumps)
|
||||
transferring data between memory and registers and transferring control (conditional or unconditional jumps).\\
|
||||
Note that \verb|move| instructions \textit{cannot} move data directly from memory to memory.
|
||||
|
||||
Most of the memory-related instructions in \texttt{x86} assembly have the format
|
||||
\mint{asm}|movq dest, src|
|
||||
whereas arithmetic / logic operations have the format inversed (below \texttt{X} is to be replced with size postfix).
|
||||
|
||||
Arithmetic / logic operations have the format inversed (below \texttt{X} is to be replced with size postfix).
|
||||
\begin{tables}{lll}{Mnemonic & Format & Computation}
|
||||
\texttt{addl} & \texttt{Src, Dest} & \texttt{Dest} $\gets$ \texttt{Dest + Src} \\
|
||||
\texttt{subX} & \texttt{Src, Dest} & \texttt{Dest} $\gets$ \texttt{Dest - Src} \\
|
||||
|
||||
15
semester3/spca/parts/00_asm/04_control-flow.tex
Normal file
15
semester3/spca/parts/00_asm/04_control-flow.tex
Normal file
@@ -0,0 +1,15 @@
|
||||
\newpage
|
||||
\subsection{Control Flow}
|
||||
|
||||
Control flow structures from \verb|C| like \verb|if/else| or \verb|for| are compiled into assembly mainly using jumps and conditional \verb|move|.
|
||||
|
||||
By the nature of Assembly and thanks to compilers optimizing aggressively, there is no \textit{single} definitive translation of the \verb|C| control structures: The compiler may translate it very differently depending on the context of the program.
|
||||
|
||||
\subsubsection{Conditional statements}
|
||||
A function using an \verb|if/else| construct to choose the maximum of $2$ numbers might compile like this:
|
||||
|
||||
\inputcodewithfilename{gas}{code-examples/01_asm/}{02_max.s}
|
||||
|
||||
A function computing the absolute difference $|x-y|$ using an \verb|if/else| construct, might use a conditional \verb|move| instead:
|
||||
|
||||
\inputcodewithfilename{gas}{code-examples/01_asm/}{03_absdiff.s}
|
||||
Reference in New Issue
Block a user