2 ms·
ASM is ridiculously shallow, but broad. You don't need to understand a whole lot to understand the basic 'mechanics'. You just need a really good reference for
by junon 5y ago
ASM is ridiculously shallow, but broad. You don't need to understand a whole lot to understand the basic 'mechanics'. You just need a really good reference for the actual instructions.
First, realize what a CPU actually does. Realize what machine code does. Learn the parts of the CPU (roughly speaking) - instructions, pointers, registers, flags, etc. Learn some basic EE concepts such as what "high" and "low" mean, and what a "line" is, for example. It's a prerequisite to reading some of the meatier bits of documentation.
Secondly, reading the CPU guides for whatever ISA (Google "AMD programmer manual volume 3" for x86_64 platforms for example) is a great start. They're full of useful information, and AMD's in particular is very easy to read, albeit large. Skim through it, especially the first bits that explain what the registers are.
Then use NASM to write a simple program that exits 42. Get there first. Learn what the different directives mean (e.g. `.text` for ELF output).
Then start to add instructions and play with registers. Learn about calling conventions. Write some C code and emit S files (google it) to see how it compiles down to machine code (turn of optimizations when you're starting out).
Get familiar with Godbolt.org, it'll help with the last thing on that list.
Any book is going to help, though pay attention to the syntax it uses (avoid GAS syntax, in my opinion) and the platform it targets (make sure you have access to that platform, e.g. don't pick up an ARM book if you're on x86). It'll make things very hard to follow if you don't.
These are just tips, but maybe they help just a bit.