2

Ask HN: Which books/resources to understand modern Assembler?

 3 weeks ago
source link: https://news.ycombinator.com/item?id=40104823
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ask HN: Which books/resources to understand modern Assembler?

Ask HN: Which books/resources to understand modern Assembler?
58 points by throwaway63467 3 hours ago | hide | past | favorite | 14 comments
I’d like to learn more about Assembler in order to be able to work with LLVM and JIT as well as to write high performance low-level code. I’m familiar with the basics of x86 but I haven’t touched Assembler in a while, so I’m wondering which resources and in particular books you’d recommend?
'Computer Architeture: A Quantitative Apporach" and/or more specific design types (mips, arm, etc) can be found under the Morgan Kaufmann Series in Computer Architeture and Design.

"Getting Started with LLVM Core Libraries: Get to Grips With Llvm Essentials and Use the Core Libraries to Build Advanced Tools "

"The Architecture of Open Source Applications (Volume 1) : LLVM" https://aosabook.org/en/v1/llvm.html

"Tourist Guide to LLVM source code" : https://blog.regehr.org/archives/1453

llvm home page : https://llvm.org/

llvm tutorial : https://llvm.org/docs/tutorial/

llvm reference : https://llvm.org/docs/LangRef.html

learn by examples : C source code to 'llvm' bitcode : https://stackoverflow.com/questions/9148890/how-to-make-clan...

How I learned:

Step #1: read the arch manual for some CPU. Read most if not all of it. It’s a lot of reading but it’s worth it. My first was PowerPC and my second was x86. By the time I got to arm, I only needed to use the manual as a reference. These days I would start with x86 because the manuals are well written and easily available. And the HW is easily available.

Step #2: compile small programs for that arch using GCC, clang, whatever and then dump disassembly and try to understand the correspondence between your code and the instructions.

s.gif
The Godbolt compiler explorer can be very helpful for step 2 there. It's neat to see how different compilers codegen the same source.
Play through the game Turing Complete, by the end you'll have built your own ISA and solved some puzzles with it. Keep playing for to get on the high scores list and you'll turn those assembly routines into ASICs.
I like this book, it's just as good as The Art of Assembly Language, but much cheaper: https://rayseyfarth.com/asm/index.html

If you are interested in ARM or RISC-V assembly, the concepts are pretty similar but the instructions are different. For any architecture, you're going to have to read the architecture manuals to get a good working knowledge of the instructions and how to use them. An easy way to get started is to write a program in C, then replace the functions with assembly code one by one until your C code is just main() and a header.

ARMv7: https://developer.arm.com/documentation/100076/0200/a32-t32-...

ARMv8: https://developer.arm.com/documentation/ddi0602/2024-03/Base...

alternative: https://www.scs.stanford.edu/~zyedidia/arm64/

RISC-V: https://riscv.org/technical/specifications/

x86: https://www.intel.com/content/www/us/en/developer/articles/t...

web format: http://x86.dapsen.com/

If you like to learn by example (most of these are not great, but good enough to get started):

https://rosettacode.org/wiki/Assembly

https://github.com/TheAlgorithms/AArch64_Assembly

I don't have a good book to suggest, but one tip you may find helpful:

A typical function has two kinds of assembly code:

(1) The ABI-required logic for functions and function calls, and

(2) Everything else, which can be more or less whatever you want. As long as you don't stomp on the details required by the ABI.

I wrote a blog post on writing a JIT that can handle FFI calls: http://blog.vmchale.com/article/jit

If you want the full monty, I think you'll have to read the LLVM documentation on JIT linking: https://llvm.org/docs/JITLink.html

I haven't found any academic papers or tutorials on JIT linking, unfortunately.

There are two aspects to assembler. One is the target machine - learning what instructions, memory, performance characteristics you're dealing with.

The other is the assembler - what syntax it gives you, how it handles macros, whether it optimises, whether it does any semantic analysis. GNU AS is different to NASM is different to flat assembler.

I didn't get much out of reading compiler disassembly relative to handwritten assembly. I'd recommend trying to find some of the latter, might need to be maths libs or video codecs or similar. I'd be interested in recommendations here, the asm I learned from was proprietary.

For those who want to do x86 assembly first, google Paul Carter assembly language.

It could be one option.

I'd suggest working incrementally from areas of your existing strength. Tweak whatever code base you are most familiar with, starting with a tiny change, and see how the assembly changes. I use objdump -d and git diff --no-index for this all the time.
A great way to learn assembler is to closely examine code generated by a compiler, e.g. on godbolt.org.
Aside from what has already been suggested, you could consider reading selected chapters of Intel's programmer manual. I personally read through the whole thing once (well, skimmed some parts).

From my experience, Intel's x86 manual is better and easier to read than AMD's. It's a free download.

s.gif
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search:

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK