Friday, December 25, 2015

Where should I start learning Assembly?

Where should I start learning Assembly?


Code by Charles Petzold [1] is a fantastic introduction. It isn't so much the nitty gritty "this opcode performs this operation, and these are all the tricks to making it do things, edge cases and things you should worry about" and more along the lines of "what opcodes should a CPU have, and how do those translate into electricity flowing through physical wires?" I feel like really thinking through that book made MIPS and x86 assembly much easier for me.

http://www.charlespetzold.com/code/

In addition, if you like "Code", I'd recommend The Pattern on the Stone by Danny Hillis (creator of Thinking Machines' Connection Machine supercomputer).

It's much shorter than "Code" but covers basically the same ground much more quickly, but Code might be better first because it really explains it thoroughly.
===
If you already know C, you can start out by looking at the machine code generated by your compiler with "objdump -d" on Linux and "otool -tV" on Mac. Start experimenting by writing out C constructs like functions, loops, switch statements, etc., and just looking at what the generated code looks like.

Of course, to do that, you need to find the manual for your machine architecture. The x86 manuals are, for example, available here:

http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html

You also then start to notice things like the operating system specific application binary interfaces (ABI):

http://www.x86-64.org/documentation/abi.pdf

and object file formats such as ELF that's used in Linux:

http://www.skyfree.org/linux/references/ELF_Format.pdf

or Mach-O used in Mac OS X:

https://developer.apple.com/library/mac/documentation/developertools/conceptual/machoruntime/reference/reference.html

You can also do the same thing with the JVM and look at its JIT-generated machine code with the '-XX:+PrintCompilation' option:

http://stackoverflow.com/questions/13086690/understanding-the-output-of-xxprintcompilation

Reference:

https://news.ycombinator.com/item?id=7143186

No comments: