# Good book on modern x86_64 architecture



## Holger (Sep 14, 2020)

Hi,

sorry, if this topic doesn't quite fit here, but I think this could be interesting for others as well.

I'm looking for a good book on modern x86 architecture. It should explain the relevant concepts, e.g. Protected Mode, virtual memory, assembly language, interfacing with modern compilers, etc.

Does such a book exist? What is your source of choice in that regard?

The idea is to gain the foundation for advanced FreeBSD hacking and low-level software development.

Thanks!


----------



## unitrunker (Sep 14, 2020)

Intel:









						Intel® 64 and IA-32 Architectures Software Developer Manuals
					

These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 architectures.




					software.intel.com
				




AMD:









						Developer Guides, Manuals & ISA Documents - AMD
					

Developer guides, reference manuals & ISA documents for the AMD A10, A8, A6 7000 Series APUs, CodeXL, Radeon, AMD64 Architecture, compilers, bios and kernel guides & more.




					developer.amd.com


----------



## bookwormep (Sep 15, 2020)

"Architecture and Programming of Intel X86 Family 40th ed." by Patrick Stakem; ISBN: 1983189405.


----------



## a6h (Sep 15, 2020)

There are not many good books on the market for modern Intel64 architecture. Most of the good assembly and system programming book are old and are targeted to 16b/DOS and 32b/Linux. Generally they are targeted toward NASM/Linux users. On the other hand the official Intel64/IA-32 documentations is over 10,500 pages! I don't see that as a problem, but it something that you should be aware of. It's getting worse if you want to learn FASM (flat assembler), any good books on fasm? there's next to nothing!
Thus let's go heuristic!

Assemblers and syntax

First of all, take your time and study about different assemblers and syntax. Do your own research, pick one of them and stick to that for a while (not for good!) I have my preferences, you should find yours. There are two syntax AT&T and Intel, search online to learn about it. About assemblers:

MASM uses Intel syntax and it's targeted to Windows users. There are two type of MASM: 16/32b and 64b(ml64.exe).
GAS/gas/as: It's GNU/GCC and it supports both Intel and AT&T (since version 2.0) syntax.
NASM is using the Intel syntax and it's the one that is used in the FreeBSD books/developers-handbook
Most people are using NASM. I'm using it too.

FASM is a Intel syntax assembler too. It's similar to NASM. It has multi pass mechanism toward better optimisation.
My favourite!

And there're other assemblers too:
HLA (waste of time)
TASM (3.5-inch disk era)
YASM (I'm not familiar)
_ellipsis_

Some points, facts and unverified claims! on assemblers

NASM has easer syntax.
NASM macros are very similar to C macros.
Many C programmers prefer to work with NASM.
GAS can uses C-style comments /* ! */
GAS is better integrated into GCC toolchain
Some people consider FASM as very Low-Level. I don't why, but that's what they are saying!
The Art of Assembly Language, the overrated book on assembly is trying to promote HLA. Frankly go learn C!
A nice comparison chart on osdev.org: https://wiki.osdev.org/Tool_Comparison
Downloading Intel 64 and IA-32 Architectures Software Developer Manuals

You can download the whole set from intel website in three different sets (all content is identical in each set)
A combined 10 volume set: vol. 1, 2(A-D), 3(A-D), 4 plus a bug fix errata
Four-volume set
volume 1:
volume 2A, 2B, 2C and 2D
volume 3A, 3B, 3C and 3D
volume 4

Ten-volume set (separated volume)

I suggest to download all of them (~121 MB in total)
Volume 2 is the most important volume for your study. It covers Instruction Set
A roadmap (FreeBSD oriented approach)

Read The Classic Four FreeBSD documentations:
FreeBSD Handbook
FreeBSD Porter's Handbook
FreeBSD Developers' Handbook
FreeBSD Architecture Handbook
If it is possible buy and read a copy of _The Design and Implementation of the FreeBSD Operating System 2nd_ by Marshall Kirk MCKusick


General information about computer architecture is very helpful:
My suggestion: _Structure Computer Organization_ by Andrew Tanenbaum.

Based on your favourite assembler/syntax, choose one of the following books, and in the mean time actively apply the FreeBSD conventions to your practice, using mentioned FreeBSD documentations (be FreeBSD specific):
Assembly Language for x86 Processors by Kip Irvine
Assembly Language Step-by-Step by Jeff Duntemann
X86 Assembly Language and C Fundamentals by Joseph Cavanagh

While you are reading one of those book, refer to 2nd volume of _Intel 64 and IA-32 Architectures Software Developer Manuals_. It covers all instruction set (ISA)
No book on the face of the earth will cover it completely. The only comprehensive book is Intel official documentations.

You need to get familiar and work with a debugger. Do you research and choose one. I have no recommendation (lldb?)
Learn about target architecture by reading through CPU manufacturer documentations.
Architecture (ISA, uarch, etc) is the king.
Assembly is the queen.
I'm not downplaying other programming languages. Don't take it personally. This specific thread is all about low-level operations.

Languages are just sledgehammers:
What's the sign of "lack of knowledge"?
Searching for X vs Y (e.g. php vs. python) on the internet, and reading the result on the Stackoverflow!
Do yourself a favour and "/etc/hosts block" such websites (stackoverflow, reddit, quora, etc)


/usr/src is your free laboratory!
Subscribe to a few mailing lists or read them online:
freebsd-arch
freebsd-current
freebsd-hackers
etc.

There's no problem with using full-feature GUI IDE for production, but they are ABS brakes in learning process. Stick to CLI and use native FreeBSD base tools.
Study system calls (section 2 of the man pages) in every step, break things and use debuggers, especially Dtrace(1) and lldb(1)


----------



## a6h (Sep 18, 2020)

vigole said:


> Assembly Language Step-by-Step by Jeff Duntemann


I should mention though, there's a problem with Duntemann book, in entire book he tries to be funny and telling tasteless stories. Unfortunately he's not a funny guy. Thus reading that book may be a little irritating for some people including me. But on the whole it's a good product.


----------



## Holger (Sep 23, 2020)

Thank you all for your answers so far!

When doing a little research, I also found this:
http://www.egr.unlv.edu/~ed/assembly64.pdf

It's a publicly available book, quite modern (from 2020), covering 64 bit assembly and some important topics like calling conventions, stack frames and parallelism.

It's somewhat Linux-centric, but I think it's okay.


----------

