May 2006
M T W T F S S
« Apr   Jun »
1234567
891011121314
15161718192021
22232425262728
293031  

May 9, 2006

Win32 Assembly Cheat Sheet

Filed under: Assembly language — Peter Kankowski @ 8:39 am

Here is a beta version of my cheat sheet for assembly programmers. It’s intended for 32-bit Windows programming with FASM. One A4 page contains almost all general-purpose x86 instructions (except FPU, MMX and SSE instructions). You will find various kinds of moves (MOV, CMOV, XCHG), arithmetical (ADD, SUB, MUL, DIV) and logical (AND, OR, XOR, NOT) instructions here. Several charts illustrate shifts (SHL/SHR, ROL/ROR, RCL/RCR) and stack frames. Code samples for typical high-level language constructs (if conditions, while and for loops, switches, function calls) are shown. Also included are quick references for RDTSC and CPUID instructions, description of string operations such as REP MOVSB, some code patterns for branchless conditions, a list of registers that should be saved in functions, and a lot of other useful stuff. The idea was to put all reference information about x86 assembly language on the one page. Some rarely-used instructions such as LDS, BOUNDS or AAA are skipped.

A chunk of cheat sheet showing multiplication and division reference

The cheat sheet use common notation for operands: reg means register, [mem] means memory location, and imm is an immediate operand. Also, x, y, and z denote the first, the second, and the third operand. Instruction mnemonics are written in capital letters to make them easier to find when you are skipping through the cheat sheet.

For example, let’s look at multiplication and division section. There are instructions for signed (IMUL) and unsigned (MUL) multiplication. Both instructions take one operand, which may be register (reg) or memory ([mem]). There are three possible cases:

  • If operand size is one byte, MUL or IMUL multiplies it by al and stores the result in ax
  • If operand size is a word, MUL or IMUL multiplies it by ax and stores the high-order word of the result in dx and the low-order word in ax.
  • If operand size is a double word, MUL or IMUL multiplies it by eax and stores the high-order dword in edx and the low-order dword in eax.

There are also two-operand and three-operand forms of IMUL shown on the picture above.

Other features of assembly language are described in a similar way. You can print the cheat sheet and put it on your table to look for some instructions when you forget them. Hope you will like it. Your comments and corrections are welcomed!

Win32 Assembly Cheat Sheet (PNG picture, 770 Kb)

The cheat sheet is designed for A4 page size; if you print it on US Letter paper, you will get thick margins. The resolution of the pictures is 300 dpi.

Off-topic: Today our country celebrates the 61st anniversary of Victory day. I’m going to see the military parade in my city, and will post some photos afterwards.

• • •

16 Comments »

  1. Like it! Although i'm more of an OOP programmer (VB.net)

    Comment by CLibra — May 10, 2006 @ 11:38 pm
  2. Really great work, only on one sheet, thank you !

    Comment by Flaith — May 11, 2006 @ 5:45 am
  3. Nice work!
    And the FPU instructions? When will be added?

    Comment by tacam-r2 — May 11, 2006 @ 3:22 pm
  4. I plan to make another page for FPU and SSE instructions, just because there is no space for them on the current cheat sheet. If there will be two pages, you would print general-purpose instructions on one side of the A4 paper, and FPU/SSE instructions on the other side. But I still can't tell you when it will be finished, because I'm very busy now, sorry.

    Comment by Peter Kankowski — May 11, 2006 @ 6:49 pm
  5. Hi, I really like your sheet and helps me alot, I think you forgot LODS* from 'String Operations' :)

    Drop me an email if you decide to add it, gives the sheet more 'complete'-look :D

    Comment by okasvi — May 13, 2006 @ 9:31 am
  6. LODS is rarely used today, and it makes no sense with REP prefixes. LODS is also suboptimal and should be replaced with several simple instructions. You shouldn't use it in modern programs. That's why I decided to skip it.

    Note that some other instructions are not included: LOOP, JECXZ, XLAT, BOUNDS, PUSHA/POPA, LAHF, SAHF, bit operations (BT, BTS, BTR, etc.), decimal and ASCII operations (AAA, DAA, etc.), and segment registers loading (LDS, LES, etc.).

    I think it's better to include more information about modern features (say, CPUID flags) than to talk about obsolete instructions such as LODS or XLAT.

    Anyway, it's always a compromise, because you can't put all information about x86 architecture on one A4 paper sheet. You have to skip something.

    Comment by Peter Kankowski — May 14, 2006 @ 1:59 pm
  7. Oh, didnt know it wasnt used nowadays anymore :D
    I learned to use it from old tutorial.
    Anyway, are you going to make it double-paged, maybe with more hints how to use instructions?

    (I like it how it is now, but having stuff on otherside of the paper is always a plus)

    Comment by okasvi — May 14, 2006 @ 11:59 pm
  8. [...] Some corrections have been made to Win32 Assembly Cheat Sheet. Okasvi helped me to find that JE and JNE were confused, and I also found a mistake in SHRL/SHRD description.

    Pingback by smallcode»Blog Archive » Corrections in the Cheat Sheet and Source Code for Machine Code Statistics — May 18, 2006 @ 6:32 pm
  9. I found two similar papers:
    * Intel Assembler x86 CodeTable lists popular x86 instructions on two pages. It also includes a diagram of the registers and a simple 16-bit program.
    * New complete x86 and x87 reference consists of a large table with opcode, description, and modified flags for each instruction. It is intended for both on-screen viewing and printing.

    Comment by Peter Kankowski — June 4, 2006 @ 10:21 am
  10. I've just entered this new world and I found everything fantastic!

    Comment by victor — February 18, 2007 @ 4:51 pm
  11. Thank you for kind words, Victor, and - welcome to SmallCode. If you will have any questions, comments, or suggestions, please don't hesitate to post them.

    Comment by Peter Kankowski — February 19, 2007 @ 10:01 am
  12. A OOP VB programmer? Wow, I wouldn't tell anyone that!

    Comment by Bbar — May 22, 2007 @ 11:10 pm
  13. [...] A subtração de valores 64 bits eu tirei daqui: http://smallcode.weblogs.us/2006/05/09/win32-assembly-cheat-sheet/ */ sub eax, dword ptr [ebp-8]; sbb edx, dword ptr

    Pingback by static_cast(double_var); « blog — February 13, 2008 @ 11:36 am
  14. excellent cheat sheet. thank you very much!

    Comment by ken — April 11, 2008 @ 4:58 am
  15. Hello. All is A4 format:

    x86 registers:
    http://www.nairam.sk/pc01.pdf

    x86 instructions:
    http://www.nairam.sk/pc03.pdf

    http://www.nairam.sk/pc05.pdf

    Comment by nairam — August 24, 2008 @ 11:14 pm
  16. Thank you! I cannot read Slovak, but your charts seem to be good for learning assembly language.

    Comment by Peter Kankowski — August 25, 2008 @ 9:20 am

Comments RSSTrackBack URI

Leave a comment

The comment form is closed. Please use wiki to post a comment.

Hosting is generously provided by: Weblogs.us • Theme by: Wench