diff --git a/semester3/spca/code-examples/01_asm/00_operations.s b/semester3/spca/code-examples/01_asm/00_operations.s index cb94e8b..c32e458 100644 --- a/semester3/spca/code-examples/01_asm/00_operations.s +++ b/semester3/spca/code-examples/01_asm/00_operations.s @@ -1,2 +1,6 @@ main: - addl 8(%rbp), %eax # Add long + movq %rax, %rdx # rax is src, rdx is dest + cmp %rax, %rdx # rax is src2, rdx is src1 + jmp func # func is label + notq %rax # rax is dest (and src) + ret # No argument diff --git a/semester3/spca/parts/00_asm/03_operations.tex b/semester3/spca/parts/00_asm/03_operations.tex index 00ee198..9f676ad 100644 --- a/semester3/spca/parts/00_asm/03_operations.tex +++ b/semester3/spca/parts/00_asm/03_operations.tex @@ -3,10 +3,11 @@ Assembly operations include performing arithmetic or logic functions on register 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| +The following instruction formats are commonly used: -Arithmetic / logic operations have the format inversed (below \texttt{X} is to be replced with size postfix). +\inputcodewithfilename{gas}{code-examples/01_asm/}{00_operations.s} + +Arithmetic / logic operations need a size postfix (replace \texttt{X} below with \texttt{b} (1B), \texttt{w} (2B), \texttt{l} (4B) or \texttt{q} (8B)). \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} \\ @@ -37,11 +38,12 @@ 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, that essentially computes $(a - b)$ without setting a destination register. +To explicitly compute them, we can use the \texttt{cmpX src2, src1} 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}, 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), 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. diff --git a/semester3/spca/spca-summary.pdf b/semester3/spca/spca-summary.pdf index be792ad..cc9b911 100644 Binary files a/semester3/spca/spca-summary.pdf and b/semester3/spca/spca-summary.pdf differ