27 comments

[ 3.7 ms ] story [ 46.4 ms ] thread
I came to the party way to late. A month ago, I found out asmjit was a thing, and now it's happily embedded in my app. But I don't know assembly! I tried to learn a few times since the early 2000s but the timing was never right. But hand written asm as a feature fits perfectly into my upcoming app, so now I am on a roll learning assembly! Here are some more resources I found so far:

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

https://sonictk.github.io/asm_tutorial/#introduction/setting...

https://cs.brown.edu/courses/cs033/docs/guides/x64_cheatshee...

https://people.freebsd.org/~lstewart/articles/cpumemory.pdf

https://learn.microsoft.com/en-us/cpp/build/x64-calling-conv...

I wish there were more articles and resources about modern ARM assembly. Not that I ever will or have programmed in Asm, but I like learning about it and imagining I will, and Intelisms feel so archaic and crusty in comparison.
I think AsmGrid has a great overview of X86 and AArch64 instructions:

  - https://asmjit.com/asmgrid/
Author here. The final part of this series is still sitting in my drafts.

It was nominally supposed to be about flow control instructions, but as it goes with those things, it spiralled and ended up touching on relocations, position-independent code, aslr... One on these days I'll clean it up and post it

(comment deleted)
>> Additionally, the higher 8 bits of rax, rbx, rcx and rdx can be referred to as ah, bh, ch and dh.

Did you mean “ax, bx, cx, dx”?

It's always a great way to get a better understanding of things but at least just poking around assembly a bit once. You do not have to make a project or anything big, but do not be afraid to check it out.
Thankfully Intel syntax.
Spectacular post, are you planning to add sections on reverse engineering executables because this definitely looks pretty close
I'd love to fool around in assembly but I can't think of anything interesting to do with it.
The software security community has a subsection that focuses on the security of compiled binaries, where understanding assembly has many uses. These uses include binary reverse engineering and proof-of-concept exploit development to demonstrate the severity of a vulnerability.

If these do sound interesting to you, I'd recommend looking into capture the flag (CTF) competitions, and trying reverse engineering or binary exploitation (pwn) challenges. PicoCTF [1] is an entry-level platform that hosts challenges and has references to learning resources - I believe there's a sequence on assembly in the learning resources.

Aside, I also find it useful to know assembly when debugging C/C++ code, as others have suggested.

[1] https://play.picoctf.org

Microcontroller and LEDs. And maybe buttons. Keep it to 8-bit and chances are you'll be able to navigate the ISA comfortably pretty quickly.
I had quite entertaining session with ChatGPT and recursive fibonacci in nasm. We found out that C-version was twice as fast. So no returning back to year 1975.

"Higher language version is easier to optimize, because machine gets better idea what you are aiming at." said Lex Fridman et al.

Thought this was the perfect place to share a project I've been working on for a few years: https://asm-editor.specy.app

It's an interactive online IDE for many assembly languages, currently M68K, MIPS, RISC-V and X86 (I need to improve X86). It has a ton of features that are made to teach assembly programming, and it can be embedded in other websites.

This is really cool! thank you!
I tried optimizing my CPU emulator dispatch in raw assembly to see if I could run a simple fibonacci program faster than C++. And I was not even close. In the end I merged it and made it a default-disabled dispatch option, because ... there has to be a way to make it faster!

If you are daring, you can find my puny attempt here: https://github.com/libriscv/libriscv/blob/master/lib/librisc...

I did manage to improve it once I figured out some of the various modes of accessing memory, and I even managed to cut the jump table down from 64- to 32-bit which should help keep it in memory. I made the jump table part of .text in order to make it RIP-relative. For the fibonacci sequence program, not many bytecodes are needed. I would greatly appreciate some tips on what can be improved there.

From the profile picture I thought that was junferno for a second.
I did not know that pointer indexing registers had direct low byte access, like `si/esi` (in 16/32bit when I last time used assemblers directly) that comes with `sil` as `ax/eax` analogy to `al`. Are there really opcodes for that that were added in the later evolution of x86_64? Seems I need to double check the specs of the platform again... out of plain curiosity!
This is the kind of introduction I was looking for! I'm currently learning a bit more about this instruction set, so that's perfect.

Also, there are so many great resources in the comments.

Great opportunity to share an older project:

https://www.AssemblyArena.com - an educational game for people who would like to learn and/or program in assembly.

It's a (non mobile-optimized) web-based PvP assembly programming game. The syntax is highly inspired by x86 assembly and the game itself by Core War. There is also a small tutorial and a ranked ladder powered by Glicko-2.

Source Code:

https://github.com/m2w4/assembly-arena

This article made me realize that, at my home, out of 7 full-fledged computers, that is, notebooks, servers or desktops, there's not a single X86 machine. Maybe there are a couple old dell notebooks somewhere in the garage, but I am not even sure they still boot.