Compare commits

..

No commits in common. "38b0c5ee6e8acef51eef756b2d976f941987f67f" and "08f7aa05c2bbb785e17f769db6c0f9355b22f33e" have entirely different histories.

209
main.tex
View File

@ -1,13 +1,11 @@
\documentclass[a4paper]{article} \documentclass[a4paper,twocolumn]{article}
\usepackage{booktabs}
\usepackage{baskervald} \usepackage{baskervald}
\usepackage{courierten} \usepackage{courierten}
\usepackage{cuted} \usepackage{cuted}
\usepackage[hmargin=2.5cm,vmargin=3.5cm]{geometry} \usepackage[margin=2cm]{geometry}
\usepackage{helvet} \usepackage{helvet}
\usepackage{mathtools} \usepackage{mathtools}
\usepackage{multicol}
\usepackage{sectsty} \usepackage{sectsty}
\usepackage{tabularx} \usepackage{tabularx}
@ -18,12 +16,10 @@
\begin{document} \begin{document}
\begin{center} \begin{strip}
\LARGE \bfseries AMD64 Cheatsheet \centering \LARGE \bfseries AMD64 Cheatsheet
\vspace{1em} \vspace{1em}
\end{center} \end{strip}
\begin{multicols}{2}
\newlength{\colwidth} \newlength{\colwidth}
\setlength{\colwidth}{\linewidth} \setlength{\colwidth}{\linewidth}
@ -31,127 +27,96 @@
\section{Instructions} \section{Instructions}
\noindent\begin{tabularx}{\colwidth}{>{\ttfamily}l>{\ttfamily}l>{$}X<{$}} \begin{tabularx}{\colwidth}{|>{\ttfamily}l|>{$}X<{$}|}
\toprule \hline
\multicolumn{3}{>{\sffamily\bfseries}c}{Arithmetic \& Logic} \\ add \ S,D & D \leftarrow S + D \\ \hline
\midrule sub \ S,D & D \leftarrow D - S \\ \hline
add & S,D & D \leftarrow S + D \\ neg \ D & D \leftarrow -D \\ \hline
sub & S,D & D \leftarrow D - S \\ inc \ D & D \leftarrow D + 1 \\ \hline
neg & D & D \leftarrow -D \\ dec \ D & D \leftarrow D - 1 \\ \hline
inc & D & D \leftarrow D + 1 \\ imul S,D & D \leftarrow S \times D \\ \hline
dec & D & D \leftarrow D - 1 \\ idiv S & \mathtt{rax} \leftarrow \lfloor\mathtt{rdx}:\mathtt{rax} \div S\rfloor \\
imul & S,D & D \leftarrow S \times D \\ & \mathtt{rdx} \leftarrow (\mathtt{rdx}:\mathtt{rax})\mod{S} \\ \hline
idiv & S & \mathtt{rax} \leftarrow \lfloor\mathtt{rdx}:\mathtt{rax} \div S\rfloor \\ \hline
& & \mathtt{rdx} \leftarrow (\mathtt{rdx}:\mathtt{rax})\mod{S} \\ and S,D & D \leftarrow S \mathbin{\&} D \\ \hline
and & S,D & D \leftarrow S \mathbin{\&} D \\ or \ S,D & D \leftarrow S \mathbin{|} D \\ \hline
or & S,D & D \leftarrow S \mathbin{|} D \\ xor S,D & D \leftarrow S \wedge D \\ \hline
xor & S,D & D \leftarrow S \wedge D \\ not D & D \leftarrow \mathord{\sim} D \\ \hline
not & D & D \leftarrow \mathord{\sim} D \\ sal n,D & D \leftarrow D \ll n \\ \hline
sal & n,D & D \leftarrow D \ll n \\ shr n,D & D \leftarrow D \gg n \hspace{1em} \textrm{(logical)} \\ \hline
shr & n,D & D \leftarrow D \gg n \hspace{1em} \textrm{(logical)} \\ sar n,D & D \leftarrow D \gg n \hspace{1em} \textrm{(arithmetic)} \\ \hline
sar & n,D & D \leftarrow D \gg n \hspace{1em} \textrm{(arithmetic)} \\ \hline
\midrule lea S,D & D \leftarrow \mathrm{addressof}(S) \\ \hline
\multicolumn{3}{>{\sffamily\bfseries}c}{Data transfer} \\ mov S,D & D \leftarrow S \\ \hline
\midrule \hline
lea & S,D & D \leftarrow \mathrm{addressof}(S) \\ cmp \ A,B & B - A \hspace{1em} \textrm{(setting cond. flags)} \\ \hline
mov & S,D & D \leftarrow S \\ test A,B & A \mathbin{\&} B \hspace{1em} \textrm{(setting cond. flags)} \\ \hline
\midrule \hline
\multicolumn{3}{>{\sffamily\bfseries}c}{Conditionals \& Branches} \\ jmp l & \textrm{jump unconditionally} \\ \hline
\midrule je \ l & \textrm{jump if equal} \\ \hline
cmp & A,B & B - A \hspace{1em} \textrm{(setting cond. flags)} \\ jne l & \textrm{jump if not equal} \\ \hline
test & A,B & A \mathbin{\&} B \hspace{1em} \textrm{(setting cond. flags)} \\ js \ l & \textrm{jump if negative} \\ \hline
jmp & l & \textrm{jump to \texttt{l} unconditionally} \\ jns l & \textrm{jump if non-negative} \\ \hline
je & l & \textrm{jump to \texttt{l} if equal} \\ jg \ l & \textrm{jump if greater} \\ \hline
jne & l & \textrm{jump to \texttt{l} if not equal} \\ jge l & \textrm{jump if greater or equal} \\ \hline
js & l & \textrm{jump to \texttt{l} if negative} \\ jl \ l & \textrm{jump if lesser} \\ \hline
jns & l & \textrm{jump to \texttt{l} if non-negative} \\ jle l & \textrm{jump if lesser or equal} \\ \hline
jg & l & \textrm{jump to \texttt{l} if greater} \\ ja \ l & \textrm{jump if above} \\ \hline
jge & l & \textrm{jump to \texttt{l} if greater or equal} \\ jae l & \textrm{jump if above or equal} \\ \hline
jl & l & \textrm{jump to \texttt{l} if lesser} \\ jb \ l & \textrm{jump if below} \\ \hline
jle & l & \textrm{jump to \texttt{l} if lesser or equal} \\ jbe l & \textrm{jump if below or equal} \\ \hline
ja & l & \textrm{jump to \texttt{l} if above} \\ \hline
jae & l & \textrm{jump to \texttt{l} if above or equal} \\ push S & \mathtt{rsp} \leftarrow \mathtt{rsp} - \mathrm{sizeof}(S) \\
jb & l & \textrm{jump to \texttt{l} if below} \\ & \mathrm{at}(\mathtt{rsp}) \leftarrow S \\ \hline
jbe & l & \textrm{jump to \texttt{l} if below or equal} \\ pop \ D & D \leftarrow \mathrm{at}(\mathtt{rsp}) \\
\midrule & \mathtt{rsp} \leftarrow \mathtt{rsp} + \mathrm{sizeof}(S) \\ \hline
\multicolumn{3}{>{\sffamily\bfseries}c}{Stack operations} \\ callq l & \textrm{push instruction pointer then jump} \\ \hline
\midrule retq & \textrm{pop to instruction pointer} \\ \hline
push & S & \mathtt{rsp} \leftarrow \mathtt{rsp} - \mathrm{sizeof}(S) \\
& & \mathrm{at}(\mathtt{rsp}) \leftarrow S \\
pop & D & D \leftarrow \mathrm{at}(\mathtt{rsp}) \\
& & \mathtt{rsp} \leftarrow \mathtt{rsp} + \mathrm{sizeof}(S) \\
callq & l & \textrm{push \texttt{rip} then jump to \texttt{l}} \\
retq & & \textrm{pop to \texttt{rip}} \\
\bottomrule
\end{tabularx} \end{tabularx}
\noindent\begin{tabularx}{\colwidth}{lX} \vspace{0.5em}
\toprule
\multicolumn{2}{>{\sffamily\bfseries}c}{Addressing Modes} \\ \noindent\begin{tabularx}{\colwidth}{|c|l|c|c|X|}
\midrule \multicolumn{2}{c}{\textbf{Suffixes}} & \multicolumn{1}{c}{} & \multicolumn{2}{c}{\textbf{Condition flags}} \\ \cline{1-2} \cline{4-5}
Immediate & \texttt{\$C} \\ b & 8 bits & & ZF & Zero \\ \cline{1-2} \cline{4-5}
Register & \texttt{\%R} \\ w & 16 bits & & SF & Sign (set on negative) \\ \cline{1-2} \cline{4-5}
Memory & \texttt{[C\textsubscript{d}](\%R\textsubscript{b}[,\%R\textsubscript{i}[,C\textsubscript{s}])} \\ l & 32 bits & & CF & Carry (unsigned overflow) \\ \cline{1-2} \cline{4-5}
\bottomrule q & 64 bits & & OF & Overflow (signed overflow) \\ \cline{1-2} \cline{4-5}
\end{tabularx} \end{tabularx}
\[\textrm{Memory Address} = C_d + R_b + C_sR_i\] \section{Addressing Modes}
\noindent\begin{center} \begin{tabularx}{\colwidth}{|l|X|}
\begin{tabular}{cl} \hline
\toprule Immediate & \texttt{\$C} \\ \hline
\multicolumn{2}{>{\sffamily\bfseries}c}{Suffixes} \\ Register & \texttt{\%R} \\ \hline
\midrule Memory & \texttt{[C\textsubscript{d}](\%R\textsubscript{b}[,\%R\textsubscript{i}[,C\textsubscript{s}])} \\ \hline
b & 8 bits \\ \end{tabularx}
w & 16 bits \\
l & 32 bits \\ \vspace{0.5em}
q & 64 bits \\
\bottomrule \[\mathrm{address} = C_d + R_b + C_sR_i\]
\end{tabular}
\hspace{1em}
\begin{tabular}{cl}
\toprule
\multicolumn{2}{>{\sffamily\bfseries}c}{Condition Flags} \\
\midrule
ZF & Zero \\
SF & Sign (set on negative) \\
CF & Carry \\
OF & Overflow \\
\bottomrule
\end{tabular}
\end{center}
\section{Registers} \section{Registers}
\begin{tabularx}{\colwidth}{>{\ttfamily}c>{\ttfamily}c>{\ttfamily}c>{\ttfamily}cX} \begin{tabularx}{\colwidth}{|>{\ttfamily}l|>{\ttfamily}l|>{\ttfamily}l|>{\ttfamily}l|X|}
\toprule \hline
\multicolumn{5}{>{\sffamily\bfseries}c}{Standard} \\ rax & eax & ax & al & accumulator \\ \hline
\midrule rbx & ebx & bx & bl & data pointer \\ \hline
rax & eax & ax & al & Accumulator \\ rcx & ecx & cx & cl & counter \\ \hline
rbx & ebx & bx & bl & DS data pointer \\ rdx & edx & dx & dl & I/O pointer \\ \hline
rcx & ecx & cx & cl & Counter \\ rsi & esi & si & sil & source pointer \\ \hline
rdx & edx & dx & dl & I/O pointer \\ rdi & edi & di & dil & destination pointer \\ \hline
rsi & esi & si & sil & Source pointer \\ rsp & esp & sp & spl & stack pointer \\ \hline
rdi & edi & di & dil & Dest. pointer \\ rbp & ebp & bp & bpl & base pointer \\ \hline
\midrule r8 & r8d & r8w & r8b & general purpose \\ \hline
\multicolumn{5}{>{\sffamily\bfseries}c}{Stack} \\ r9 & r9d & r9w & r9b & general purpose \\ \hline
\midrule r10 & r10d & r10w & r10b & general purpose \\ \hline
rsp & esp & sp & spl & Stack pointer \\ r11 & r11d & r11w & r11b & general purpose \\ \hline
rbp & ebp & bp & bpl & Base pointer \\ r12 & r12d & r12w & r12b & general purpose \\ \hline
\midrule r13 & r13d & r13w & r13b & general purpose \\ \hline
\multicolumn{5}{>{\sffamily\bfseries}c}{64-bit Mode Only} \\ r14 & r14d & r14w & r14b & general purpose \\ \hline
\midrule r15 & r15d & r15w & r15b & general purpose \\ \hline
r8 & r8d & r8w & r8b & \multicolumn{1}{c}{\textendash} \\
r9 & r9d & r9w & r9b & \multicolumn{1}{c}{\textendash} \\
r10 & r10d & r10w & r10b & \multicolumn{1}{c}{\textendash} \\
r11 & r11d & r11w & r11b & \multicolumn{1}{c}{\textendash} \\
r12 & r12d & r12w & r12b & \multicolumn{1}{c}{\textendash} \\
r13 & r13d & r13w & r13b & \multicolumn{1}{c}{\textendash} \\
r14 & r14d & r14w & r14b & \multicolumn{1}{c}{\textendash} \\
r15 & r15d & r15w & r15b & \multicolumn{1}{c}{\textendash} \\
\bottomrule
\end{tabularx} \end{tabularx}
\end{multicols}
\end{document} \end{document}