\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Kzderrick} \pdfinfo{ /Title (x86-assembly.pdf) /Creator (Cheatography) /Author (Kzderrick) /Subject (x86 assembly Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{x86 assembly Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Kzderrick} via \textcolor{DarkBackground}{\uline{cheatography.com/26001/cs/7101/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Kzderrick \\ \uline{cheatography.com/kzderrick} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 13th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Jump Instructions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{JZ Jump if zero ZF = 1} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{JNZ Jump if not zero ZF = 0} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{JC Jump if carry CF = 1} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{JNC Jump if not carry CF = 0} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{JO Jump if overflow OF = 1} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{JNO Jump if not overflow OF = 0} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{JS Jump if signed SF = 1} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{JNS Jump if not signed SF = 0} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{JP Jump if parity (even) PF = 1} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{JNP Jump if not parity (odd) PF = 0} \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{BYTE 8-bit unsigned integer.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SBYTE 8-bit signed integer.} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{WORD 16-bit unsigned integer} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SWORD 16-bit signed integer} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{DWORD 32-bit unsigned integer.} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SDWORD 32-bit signed integer.} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Arrays - (from book pg 120-124)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{.data \newline arrayB BYTE 10h,20h,30h \newline .code \newline mov ESI,OFFSET arrayB \newline mov AL,{[}ESI{]} \newline inc ESI \newline -{}-{}-{}-{}-{}-{}--OFFSET-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}- \newline .data \newline arrayW WORD 1000h,2000h,3000h \newline .code \newline mov ESI,OFFSET arrayW \newline mov AX,{[}ESI{]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{LOOP}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{.data \newline mov ax,0 \newline mov ecx,5 \newline .code \newline L1: \newline inc ax \newline loop L1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ASCII}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/kzderrick_1455145416_Screen Shot 2016-02-10 at 7.01.55 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{CMP Instruction}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Compares the destination operand to the source operand \newline % Row Count 2 (+ 2) Nondestructive subtraction of source from destination (destination operand is not changed) Syntax: CMP destination, source. \newline % Row Count 5 (+ 3) destination \textless{} source ....carry flag set \newline % Row Count 6 (+ 1) destination \textgreater{} source.... ZF=0, CF=0% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.71009 cm} p{0.71009 cm} x{1.46195 cm} x{1.29487 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Registers}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{32-Bit} & \seqsplit{16-Bit} & 8-bit (high) & 8 bit (low) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} EAX & AX & AH & AL \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} EBX & BX & BH & BL \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} ECX & CX & CH & CL \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} EDX & DX & DH & DL \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} ESI & SI & & \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} EDI & DI & & \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} EBP & BP & & \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} ESP & SP & & \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{FLAGS}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{• The Carry flag (CF) is set when the result of an unsigned arithmetic operation is too large to fit into the destination. \newline % Row Count 3 (+ 3) • The Overflow flag (OF) is set when the result of a signed arithmetic operation is too large or too small to fit into the destination. \newline % Row Count 6 (+ 3) • The Sign flag (SF) is set when the result of an arithmetic or logical operation generates a negative result. \newline % Row Count 9 (+ 3) • The Zero flag (ZF) is set when the result of an arithmetic or logical operation generates a result of zero. \newline % Row Count 12 (+ 3) • The Auxiliary Carry flag (AC) is set when an arithmetic operation causes a carry from bit 3 to bit 4 in an 8-bit operand. \newline % Row Count 15 (+ 3) • The Parity flag (PF) is set if the least-significant byte in the result contains an even number of 1 bits. Otherwise, PF is clear. In general, it is used for error checking when there is a possi- bility that data might be altered or corrupted.% Row Count 20 (+ 5) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{TEST Instruction}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Performs a nondestructive AND operation between each pair of matching bits in two operands.No operands are modified, but the Zero flag is affected. \newline % Row Count 3 (+ 3) Example: jump to a label if either bit 0 or bit 1 in AL is set. \newline % Row Count 5 (+ 2) test al,00000011b \newline % Row Count 6 (+ 1) jnz ValueFound% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ROT SHIFT}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{SAL (shift arithmetic left) is identical to SHL. \newline % Row Count 1 (+ 1) SAR (shift arithmetic right) performs a right arithmetic shift on the destination operand. \newline % Row Count 3 (+ 2) ROL (rotate) shifts each bit to the left \newline % Row Count 4 (+ 1) The highest bit is copied into both the Carry flag and into the lowest bit \newline % Row Count 6 (+ 2) No bits are lost \newline % Row Count 7 (+ 1) ROR (rotate right) shifts each bit to the right \newline % Row Count 8 (+ 1) The lowest bit is copied into both the Carry flag and into the highest bit \newline % Row Count 10 (+ 2) No bits are lost \newline % Row Count 11 (+ 1) RCL (rotate carry left) shifts each bit to the left \newline % Row Count 13 (+ 2) Shifts a destination operand a given number of bits to the right \newline % Row Count 15 (+ 2) The bit positions opened up by the shift are filled by the least significant bits of the source operand \newline % Row Count 18 (+ 3) The source operand is not affected \newline % Row Count 19 (+ 1) Copies the Carry flag to the least significant bit \newline % Row Count 21 (+ 2) Copies the most significant bit to the Carry flagRCR (rotate carry right) shifts each bit to the right \newline % Row Count 24 (+ 3) Copies the Carry flag to the most significant bit \newline % Row Count 25 (+ 1) Copies the least significant bit to the Carry flag \newline % Row Count 27 (+ 2) Shifts a destination operand a given number of bits to the left \newline % Row Count 29 (+ 2) The bit positions opened up by the shift are filled by the most significant bits of the source operand \newline % Row Count 32 (+ 3) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ROT SHIFT (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The source operand is not affected \newline % Row Count 1 (+ 1) Syntax: \newline % Row Count 2 (+ 1) SHLD destination, source, count% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{OR, XOR, AND, NOT}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{OR destination, source. 0,0=0. 0,1=1, 1,0=1. 1,1 = 1 \newline % Row Count 2 (+ 2) XOR destination, source. 0,0=0. 0,1=1, 1,0=1. 1,1 = 0 \newline % Row Count 4 (+ 2) NOT destination...invert all \newline % Row Count 5 (+ 1) AND destination, source 0,0=0. 0,1=0, 1,0=0. 1,1 = 1% Row Count 7 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Procedures}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{SumOf PROC \newline add EAX, EBX \newline add EAX, ECX \newline ret \newline SumOf ENDP \newline END main} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Irvine 32 lib procedures}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{DumpMemm \newline mov ESI,OFFSET array \newline mov ECX,LENGTHOF array \newline mov EBX,TYPE array \newline call DumpMem \newline \newline ReadChar \newline char BYTE ? \newline .code \newline call ReadChar \newline mov char, AL \newline \newline Random32 \newline call Random32 \newline mov randVal, EAX \newline \newline ReadDec ;same for dec, hex, int \newline intVal DWORD ? \newline .code \newline call ReadDec \newline mov intVal,eax \newline \newline ReadString \newline .data \newline buffer BYTE 21 DUP(0) ; input buffer \newline byteCount DWORD ? ; holds counter \newline .code \newline mov EDX,OFFSET buffer ; point to the buffer \newline mov ECX,SIZEOF buffer ; specify max characters \newline call ReadString ; input the string \newline mov byteCount, EAX ; number of characters \newline \newline WriteChar \newline mov AL, 'A' \newline call WriteChar \newline \newline WriteDec,hex,int \newline mov eax,295 \newline call WriteDec \newline \newline WriteString \newline .data \newline prompt BYTE "Enter your name: ",0 .code \newline mov edx,OFFSET prompt \newline call WriteString} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Unsigned Comparison}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/kzderrick_1455156455_Screen Shot 2016-02-10 at 10.07.01 PM.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{PUSHAD POPAD}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The PUSHAD instruction pushes all of the 32-bit general-purpose registers on the stack in the following order: EAX, ECX, EDX, EBX, ESP (value before executing PUSHAD), EBP, ESI, and EDI.The POPAD instruction pops the same registers off the stack in reverse order.% Row Count 6 (+ 6) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Signed}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/kzderrick_1455156473_Signed.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{MUL IMUL}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{In 32-bit mode, MUL (unsigned multiply) instruction multiplies an 8-, 16-, or 32-bit operand by either AL, AX, or EAX \newline .data \newline val1 WORD 2000h \newline val2 WORD 100h \newline .code \newline mov ax,val1 \newline mul val2 ; DX:AX = 00200000h, CF=1 \newline \newline IMUL (signed integer multiply ) multiplies an 8-, 16-, or 32-bit signed operand by either AL, AX, or EAX \newline Preserves the sign of the product by sign-extending it into the upper half of the destination register \newline \newline mov eax,4823424 \newline mov ebx,-423 \newline imul ebx ; EDX:EAX = FFFFFFFF86635D80h, OF=0} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}