\documentclass{article} \usepackage{lmodern} \usepackage[T1]{fontenc} \usepackage{geometry} \usepackage{array} \newcolumntype{@}{>{\global\let\currentrowstyle\relax}} \newcolumntype{^}{>{\currentrowstyle}} \newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}% #1\ignorespaces } % Configuración de parrafos \setlength{\parskip}{1em} % Margenes \geometry{ a4paper, total={210mm,297mm}, left=15mm, right=10mm, top=15mm, bottom=10mm, includehead, includefoot } \textwidth=6in \textheight=9.0in \begin{document} \section{Saltos} \textbf {JA} = Above/not below or equal | (CF or ZF) = 0 \\ \textbf {JAE} = Above or equal/not below | CF = 0 \\ \textbf {JE} = Equal/zero | ZF = 1 \\ \textbf {JZ} = Equal/zero | ZF = 1 \\ \textbf {JGE} = Greater or equal/not less | (SF xor OF) = 0 \\ \textbf {JG} = Greater/not less or equal | ((SF xor OF) or ZF) = 0 \\ \textbf {JO} = Overflow | OF = 1 \\ \textbf {JECXZ} = Register ECX is zero | ECX = 0 \\ \section{Registros} \begin{itemize} \setlength\itemsep{1em} \item \textbf{8 bits}: AL, BL, CL, DL, DIL, SIL, BPL, SPL, R8L, R9L, R10L, R11L, R12L, R13L, R14L, R15L \item \textbf{16 bits}: AX, BX, CX, DX, DI, SI, BP, SP, R8W, R9W, R10W, R11W, R12W, R13W, R14W, R15W \item \textbf{32 bits}: EAX, EBX, ECX, EDX, EDI, ESI, EBP, ESP, R8D, R9D, R10D, R11D, R12D, R13D, R14D, R15D \item \textbf{64 bits}: RAX, RBX, RCX, RDX, RSI, RDI, RPB, RSP, R8, R9, R10, R11, R12, R13, R14, R15 \item \textbf{128 bits}: XMM0-XMM15 \end{itemize} \section{Secciones y Etiquetas} \subsection*{Secciones} \textbf{.data}: Variables \\ \textbf{.rodata}: Constantes \\ \textbf{.text}: C\'odigo \\ \subsection*{Etiquetas} \textbf{global}: Define un s\'imbolo que va a ser visto externamente \\ \textbf{\_start}: Punto de entrada de un programa en linux \\ \textbf{extern}: Llamar funci\'on externa \subsection*{Pseudoinstrucciones} Prefijo \textbf{TIMES}, para repetir una cantidad de veces la instrucci\'on que sigue \section*{Instrucciones} \begin{tabular}[l]{ |@l|>{\itshape}^l|^l| } \hline \rowstyle{\bfseries} Instruccion & Formato & Descripcion \\ \hline DB, DW, DD, DQ & -- & Definir datos \\ SHR & reg, imm & Hace un shift right l\'ogico (sin signo) \\ SAR & reg, imm & Hace un shift right aritm\'etico (con signo) \\ LEA & reg1, [ reg * imm + imm/reg ] & Evalua lo que hay entre corchetes y lo almacena en reg1 \\ MOVZX & ???? & En las diapos decia que servia para algo \\ CBW & ???? & En las diapos decia que servia para algo \\ CDQE & ???? & En las diapos decia que servia para algo \\ MOV & (tam), mem/imm & Para el caso de inmediato o mem, especificar tam \\ CMP & (tam), mem/imm & Para el caso de inmediato o mem, especificar tam \\ MOVQ & xmm, reg & Muevo de registro a registro XMM \\ CLD & -- & Seteo flag de direcci\'on (forward) \\ REP & instruccion & Repito RCX veces la instrucci\'on siguiente \\ MOVSB & -- & Mueve el contenido de donde apunta RSI y lo almacena a donde apunta RDI, despues aumenta ¿en 1? los dos registros \\ \hline \end{tabular} \section{Convenci\'on C} \begin{itemize} \setlength\itemsep{1em} \item RBX, R12, R13, R14 y R15 \\ \item Retornar el resultado RAX o XMM0 \\ \item No romper la pila \\ \item Antes de llamar, alinear la pila a 16 bytes \\ \end{itemize} \subsection*{Stack Frame} \textbf{PUSH RBP} \\ \textbf{MOV RBP, RSP} \\ ... \\ \textbf{SUB RSP, 8 }; para alinear, variables locales \\ ... \\ ... \\ \textbf{POP RBP} \\ \textbf{RET} \\ \subsection*{Pasaje de parametros} \begin{itemize} \setlength\itemsep{1em} \item Si es entero o puntero se pasan respetando el orden usando: \begin{itemize} \setlength\itemsep{1em} \item [$*$] RDI, RSI, RDX, RCX, R8 y R9 \end{itemize} \item Si es de tipo flotante se pasan en los XMMs \end{itemize} Si no hay m\'as registros disponibles de usa la pila, pero deber\'an quedar ordenados desde la direcci\'on m\'as baja a la m\'as alta (se pushean de derecha a izquierda) \subsection*{Vectores} \textit {"Puntero al inicio del arreglo"} + \textit {"tama\~no del dato"} * \textit {" índice del elemento"} \subsection*{Matrices} \textit {"Puntero al inicio de la matriz"} + \textit {"cantidad elementos de la fila"} * \textit {"indice de la fila"} * \textit {"tama\~no dato"} + \textit {"indice de columna"} * \textit {"tama\~no dato"} \subsection*{El formato general para direccionar es} \begin{center}[ \textit{\textbf{Base}} + \textit{\textbf{Indice}} * \textit{\textbf{scala}} +/- \textit{\textbf{Desplazamiento}} ]\\ \textbf{Base} = alg\'un registro\\ \textbf{Indice} = alg\'un registro\\ \textbf{scala} = 1, 2, 4 u 8\\ \textbf{Desplazamiento} = inmediato de 32 bits\\ \end{center} \section{Alineaci\'on} \begin{itemize} \setlength\itemsep{1em} \item \textbf{Alineaci\'on en los campos del struct}: Cada campo esta alineado a su tama\~no dentro del struct \item \textbf{Alineaci\'on del struct}: Se alinea al tama\~no del campo mas grande del struct \item\textbf{\_\_atribute\_\_((packed)}: Indica que el struct no va a ser alineado \end{itemize} ------------------------------------------ \\ \section{SSE} Para enteros: Comienzan con P, luego el nombre de la \textit {"operaci\'on"} y terminan con el \textit {"tamaño"} del dato \textit {\textbf {Ejemplo}} \begin{itemize} \setlength\itemsep{1em} \item \textbf {PADDB}: suma de a \textbf{B}yte \item \textbf {PADDW}: suma de a \textbf{W}ord \item \textbf {PADDD}: suma de a \textbf{D}oubleword \item \textbf {PADDQ}: duma de a \textbf{Q}uadword \end{itemize} Para punto flotante: nombre de la \textit {"operaci\'on"}, \textit {"modo"} de operaci\'on y \textit {"tama\~no"} del dato \\ \textit {\textbf {Ejemplo}} \begin{itemize} \setlength\itemsep{1em} \item \textbf {ADDPS}: suma de a \textbf{F}loat \item \textbf {ADDPD}: suma de a \textbf{D}ouble \end{itemize} La P proviene de Packed, podria ser S de Scalar \subsection*{Multiplicar} \begin{itemize} \setlength\itemsep{1em} \item \textbf {PMULLW}: multiplica de a word y se queda con la parte baja \item \textbf {PMULHW}: multiplica de a word y se queda con la parte alta \end{itemize} \subsection*{Saturacion} \begin{itemize} \setlength\itemsep{1em} \item \textbf {PADDUSB, PSUBUSB}: Suma y resta de enteros byte sin signo con saturaci\'on sin signo \item \textbf {PADDSB, PSUBSB}: Suma y resta de enteros byte con signo con saturaci\'on con signo \end{itemize} \subsection*{Empaquetado/Desempaquetado} \begin{itemize} \setlength\itemsep{1em} \item Desempaquetado: PUNPCK \{L,H\} \{BW,WD,DQ,QDQ\} \item Empaquetado: PACK{SS,US}{WB,DW}\\ SS, US: \textbf{S}igned/\textbf{u}nsigned, con \textbf{s}aturación \end{itemize} \textit{\textbf{Ejemplo}}\\ Estos de aca abajo quiero poner con item, pero si no se puede bueno \\ \textbf{PXOR} XMM7, XMM7 (este fijate si terminan los dos en 7 que por ahi me confundi por si las moscas) \\ \textbf{MOVDQU} XMM1, XMM0 \\ \textbf{PUNPCKLBW} XMM0, XMM7 \\ \textbf{PUNPCKHBW} XMM1, XMM7 \\ \subsection*{Desempaquetar} \begin{itemize} \setlength\itemsep{1em} \item \textbf{PUNPCKLWD}: usa la parte baja de los registros para juntarlos \item \textbf{PUNPCKHWD}: usa la parte alta de los registros para juntarlos \end{itemize} \subsection*{Shuffles} Las intrucciones de Shuffles permiten reordenar datos en registros. Sus par\'ametros serán el registro a reordenar y una mascara que indicar\'a como hacerlo \begin{itemize} \setlength\itemsep{1em} \item \textbf{PSHUF\{B,W,D\}}: Shuffle Packed Bytes, Words, Doublewords \item \textbf{PSHUF\{H,L\}W}: Shuffle High, low 16bit values \item \textbf{SHUFP\{S,D\}}: Shuffle Packed single, Double FP Values \end{itemize} \textbf{PSHUFHW} xmm1, xmm2/m128, imm8 \subsection*{Insert/Extract} \begin{itemize} \setlength\itemsep{1em} \item \textbf{INSERTPS}: Insert Packed Single FP Value \item \textbf{EXTRACTPS}: Extract Packed Single FP Value \item \textbf{PINSR\{B,W,D,Q\}}: Insert Byte, Word, Dword, Qword \item \textbf{PEXTR\{B,W,D,Q\}}: Extract Byte, Word, Dword, Qword \end{itemize} \textbf{INSERTPS} xmm1, xmm2/m32, imm8 \\ \textbf{EXTRACTPS} reg/m32, xmm2, imm8 \\ \textbf{PINSRD} xmm1, r/m32, imm8 \\ \textbf{PEXTRD} r/m32, xmm2, imm8 \\ \subsection*{Conversiones} Las intrucciones de conversi\'on son de la forma: CTV\textbf{XX}2\textbf{YY} \\ \textit{Donde \textbf{XX} e \textbf{YY} pueden valer:} \\ \begin{tabular}[l]{ |c|c|c| } PS-Packed Single FP & PD-Packed Double FP & PI-Packed Integer \\ PS-Packed Single FP & PD-Packed Double FP & PI-Packed Integer \\ & & DQ-Packed Dword \\ \end{tabular} \section{Instruciones} \begin{tabular}[l]{ |@l|>{\itshape}^l|^l| } \rowstyle{\bfseries} Instruccion & Formato & Descripcion \\ \hline \multicolumn{3}{ |c| }{Conversiones} \\ \hline CVTSD2SI & r64/r32, xmm/m64 & Scalar Double FP to Dword Integer \\ CVTSI2SD & xmm, r/m32/m64 & Dword Integer to Scalar Double FP \\ CVTDQ2PS & xmm1, xmm2/m128 & Packed Dword Integers to Packed Single FP (4X)\\ CVTPS2DQ & xmm1, xmm2/m128 & Packed Single FP to Packed Dword Integers (4X)\\ CVTDQ2PD & xmm1, xmm2/m64 & Packed Dword Integers to Packed Double FP (2X)\\ CVTPD2DQ & xmm1, xmm2/m128 & Packed Double FP to Packed Dword Integers (2X)\\ CVTPD2PS & xmm1, xmm2/m128 & Packed Double FP to Packed Single FP (2X)\\ CVTPS2PD & xmm1, xmm2/m64 & Packed Single FP to Packed Double FP (2X)\\ CVTSD2SS & xmm1, xmm2/m64 & Scalar Double FP to Scalar Single FP (1X)\\ CVTSS2SD & xmm1, xmm2/m32 & Scalar Single FP to Scalar Double FP (1X)\\ CVTTPS2DQ & xmm1, xmm2/m128 & Truncation Packed Single FP to Packed Dword Int. (4X)\\ CVTTSS2SI & r32, xmm/m32 & Truncation Scalar Single FP to Dword Integer (1X)\\ CVTTSD2SI & r32, xmm/m64 & Truncation Scalar Double FP to Signed Integer (1X)\\ CVTSI2SS & xmm, r/m32 & Dword Integer to Scalar Single FP\\ CVTSS2SI & r32, xmm/m32 & Scalar Single FP to Dword Integer\\ CVTPI2PS & xmm, mm/m64 & Packed Dword Integers to Packed Single FP\\ CVTPI2PD & xmm, mm/m64 & Packed Dword Integers to Packed Double FP\\ \hline \multicolumn{3}{ |c| }{Round} \\ \hline ROUNDPS & xmm1, xmm2/m128, imm8 & Round Packed Single FP to Integer\\ ROUNDSS & xmm1, xmm2/m32, imm8 & Round Scalar Single FP to Integer\\ ROUNDPD & xmm1, xmm2/m128, imm8 & Round Packed Double FP to Integer\\ ROUNDSD & xmm1, xmm2/m64, imm8 & Round Scalar Double FP to Integer\\ \hline \multicolumn{3}{ |c| }{Otros} \\ \hline PCMPGTW & xmm, xmm & Compara word a word y si cumple la condici\'on setea unos en el resultado, sino ceros \\ \end{tabular} \end{document}