nasm x86 Assembly Quick Reference ("Cheat Sheet")
Instructions
| Stack Frame(example without ebp or local variables)
my_sub: # Returns first argument mov eax,[esp+4] ret (example when using ebp and two local variables)
my_sub2: # Returns first argument push ebp # Prologue mov ebp, esp mov eax, [ebp+8] mov esp, ebp # Epilogue pop ebp ret | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Constants, Registers, Memory"12" means decimal 12; "0xF0" is hex. "some_function" is the address of the first instruction of a label.Memory access (use register as pointer): "[esp]". Same as C "*esp". Memory access with offset (use register + offset as pointer): "[esp+4]". Same as C "*(esp+4)". Memory access with scaled index (register + another register * scale): "[eax + 4*ebx]". Same as C "*(eax+ebx*4)". Subroutines are basically just labels. Here's how you declare labels for the linker:
| Registersesp is the stack pointerebp is the stack frame pointer Return value in eax Arguments are on the stack Free for use (no save needed): eax, ecx, edx Must be saved: ebp, esp, esi, edi ebx must be saved in a shared library, but is otherwise free for use. 8 bit: ah (high 8 bits) and al (low 8 bits) 16 bit: ax 32 bit: eax 64 bit: rax |
Pretty much this same syntax is used by NASM (portable x86 assembler for Windows/Linux/whatever), YASM (adds 64-bit support to NASM), MASM (the Microsoft/Macro Assembler), and the official Intel documentation below. See the NASM documentation or MASM documentation for details on constants, labels and macros. Paul Carter has a good x86 assembly tutorial using the Intel syntax. The other, nastier syntax out there is the AT&T/GNU syntax , which I can't recommend. The machine code in all cases is identical.
The Intel Software Developer's Manuals are incredibly long, boring, and complete--they give all the nitty-gritty details. Volume 1 lists the processor registers in Section 3.4.1. Volume 2 lists all the x86 instructions in Section 3.2. Volume 3 gives the performance monitoring registers in Section. For Linux, the System V ABI gives the calling convention on page 39. Also see the Intel hall of fame for historical info. Sandpile.org has a good opcode table.
Ralph Brown's Interrupt List is the aging but definitive reference for all PC software interrupt functions. See just the BIOS interrupts for interrupt-time code.