Recommended textbook for machine-level programming?
- by Norman Ramsey
I'm looking at textbooks for an undergraduate course in machine-level programming. If the perfect book existed, this is what it would look like:
Uses examples written in C or assembly language, or both.
Covers machine-level operations such as two's-complement integer arithmetic, bitwise operations, and floating-point arithmetic.
Explains how caches work and how they affect performance.
Explains machine instructions or assembly instructions. Bonus if the example assembly language includes x86; triple bonus if it includes x86-64 (aka AMD64).
Explains how C values and data structures are represented using hardware registers and memory.
Explains how C control structures are translated into assembly language using conditional and unconditional branch instructions.
Explains something about procedure calling conventions and how procedure calls are implemented at the machine level.
Books I might be interested in would probably have the words "machine organization" or "computer architecture" in the title.
Here are some books I'm considering but am not quite happy with:
Computer Systems: A Programmer's Perspective by Randy Bryant and Dave O'Hallaron. This is quite a nice book, but it's a book for a broad, shallow course in systems programming, and it contains a great deal of material my students don't need. Also, it is just out in a second edition, which will make it expensive.
Computer Organization and Design: The Hardware/Software Interface by Dave Patterson and John Hennessy. This is also a very nice book, but it contains way more information about how the hardware works than my students need. Also, the exercises look boring.
Finally, it has a show-stopping bug: it is based very heavily on MIPS hardware and the use of a MIPS simulator. My students need to learn how to use DDD, and I can't see getting this to work on a simulator. Not to mention that I can't see them cross-compiling their code for the simulator, and so on and so forth. Another flaw is that the book mentions the x86 architecture only to sneer at it. I am entirely sympathetic to this point of view, but news flash! You guys lost!
Write Great Code Vol I: Understanding the Machine by Randall Hyde. I haven't evaluated this book as thoroughly as the other two. It has a lot of what I need, but the translation from high-level language to assembler is deferred to Volume Two, which has mixed reviews. My students will be annoyed if I make them buy a two-volume series, even if the price of those two volumes is smaller than the price of other books.
I would really welcome other suggestions of books that would help students in a class where they are to learn how C-language data structures and code are translated to machine-level data structures and code and where they learn how to think about performance, with an emphasis on the cache.