25

There are lots of books on assembly. However, they usually deal with ISAs about which I don't care, such as MIPS or ARM. I don't deal with these architectures; there's no reason for me to try to learn them.

But x86 assembly books seem... nonexistent.

Let's say for example I'm trying to build a toy compiler generating Windows Portable Executable files.

Is there a book out there that's the de-facto standard for describing best practices, design methodologies, and other helpful information on x86 assembly? What about that book makes it special?

7
  • How much assembly experience do you have? Have you ever tried using GCC without optimization to compile simple C programs into assembly, then reverse engineering the code back to a C program?
    – Brian
    Aug 22, 2011 at 18:07
  • 10
    @Brian: I would need to know assembly before being able to do that. Aug 22, 2011 at 18:12
  • I have seen a copy of the x86 instruction set. It is 2 volumes, and probably the largest book I have ever seen. Have fun :)
    – AngryBird
    Aug 22, 2011 at 19:46
  • 2
    Billy, If you know no assembly at all, then any of them would be pretty good to start from to get the general ideas. Assembly is extremely close to the architecture, so the assembly instructions greatly reflect architecture-specific designs. I started with x86 assembly, and read Kip Irvine's "Assembly Language for Intel-Based Computers". The book was actually paired with an online class at a community college though. I'm not sure what kind of learner you are, but I find guided instruction works best for learning.
    – Brian
    Aug 23, 2011 at 7:29
  • @Brian: What do you mean by "any of them"? I don't understand what "them" is -- any book? Any assembler? Any ISA? I've already played with MIPS assembler; I can't find anything on x86 though. Aug 23, 2011 at 13:01

5 Answers 5

18

I used Assembly Language for x86 Processors as a textbook when I was in college and found it very easy to understand. I have the older fourth edition and compared it to the sixth edition and didn't notice much change, so you could probably pick up an older copy cheap. People complain about his use of his own library for I/O, but he tells you how to do it the "hard" way in latter chapters.

6
  • 1
    Very good book!
    – Coder
    Aug 22, 2011 at 22:40
  • I read the 5th edition of Irvine's book when it was titled "Assembly Language for Intel-Based Computers". :)
    – Brian
    Aug 23, 2011 at 7:33
  • 1
    I think this is a pretty bad suggestion, as most of the second edition is specific to the authors own esoteric system High Level Assembly which is essentially a bastardized version of C. I've never read the first edition published. The dos version which you can find on his site for free and has never been published is a great read though. It's also about 50% longer and lacks anything about HLA (which is a total waste of time). Sep 25, 2018 at 14:05
  • 1
    @EvanCarroll I'm confused. You changed the link to the wrong book, then criticized the book you changed the link to. Was that unintentional? Dec 6, 2019 at 0:07
  • 1
    totally my mistake. @MerlynMorgan-Graham good on you for both catching it and correcting it. Dec 6, 2019 at 15:47
18

The obvious place to go is Intel's website, where you can find programming and reference manuals for download that contain everything there is to know about the x86 architecture.

Here: Intel® 64 and IA-32 Architectures Software Developer's Manuals

9

The Art of Assembly Programming is an excellent resource that has quite a bit about x86 programming.

x64 ABI documentation is also useful. I was trying to find a link to the version that was on AMDs website, but I can't seem to find it anymore, so I guess this one will have to do.

Something that can help quite [a bit] while learning is, instead of trying to write a complete app from scratch in assembly, instead write most of it in C (or any other compiled language really) and then call a chunk of assembly code from that. Once you've done that, reverse it, write an assembly program, and call some C functions from that.

Edit: Fixed a typo.

1
  • 1
    Another suggestion: Write a simple program in C, compile it to assembly, clean it up so your assembler can assemble it, then enhance the assembly version. It's a good way to get some minimum functionality (read from the keyboard, write to the console) going quickly.
    – TMN
    Aug 22, 2011 at 21:23
4

A very good book for learning x86 Assembly is Pentium Processor Optimization Tools. While the book's main focus is the optimization of assembly code, it teaches Pentium assembly along the way, and is a good reference book as well.

It is long out of print but is not hard to find used.

It comes with a floppy disk containing an "assembly code optimizer". It does not actually optimize your code, but instead produces a commented listing that points out where inefficiencies such as pipeline stalls lie.

The tool that comes with a book is a limited version of a more featureful product that the author's company used to sell, but for reasons I am unfamiliar with they are long out of business. I don't know why - I would think such a tool would sell like hotcakes.

x86 in general is a very complex topic as there are many variants that are supported by different models of microprocessors. Once you know the basics you will want to consult Intel's or AMD's databooks for the precise chip you are targeting. Unfortunately code that runs fast on one model of CPU may not be as fast on a different chip.

2
  • Not really going for performance; just want to be able to generate binaries. Will still take a look :) Aug 22, 2011 at 18:13
  • 2
    You will also need to learn how to use a particular assembler, not just the assembly opcodes. Each assembler does things totally differently. If you are going to write a lot of assembly code, use masm as it was developed with human coders in mind. If you're just going to write little snippets of inline assembly, you could use gcc with GNU as (also called gas) inline assembly. GNU as' syntax is completely different from masm's. As was written primarily for use as the back end for gcc, to do the executable code generation, and so does not provide many of the features that human coders want. Aug 22, 2011 at 18:19
1

Why not try the wikibook - http://en.wikibooks.org/wiki/X86_Assembly. It gives a good introductory start to assembly language.

The hard bit about assembly is realising how simple it is, and that you need to stay with that simplicity.

Not the answer you're looking for? Browse other questions tagged or ask your own question.