# I want to learn assembler. Do I? If so x86 or arm?

**URL:** <https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328>\
**Category:** Help\
**Tags:** language\
**Created:** [May 15, 2024, 2:14pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328 "2024-05-15T14:14:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rofrol](https://ziggit.dev/user_avatar/ziggit.dev/rofrol/32/231_2.png) [@rofrol](https://ziggit.dev/u/rofrol)\
**Post date:** [May 15, 2024, 2:14pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/1 "2024-05-15T14:14:35Z")

</div>

I see many links to godbolt any people seeing clever things in the output.

Should I learn this magic to have better understanding of Zig.

If so should I learn this dying x86 or rising star arm? I work on m1 mac.

Inspired by [https://9gag.com/gag/a9yMpYm](https://9gag.com/gag/a9yMpYm)

---

<div class="post-metadata">

**Author:** ![neurocyte](https://ziggit.dev/user_avatar/ziggit.dev/neurocyte/32/3804_2.png) [@neurocyte](https://ziggit.dev/u/neurocyte)\
**Post date:** [May 15, 2024, 2:31pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/2 "2024-05-15T14:31:59Z")

</div>

Both?

If you want to have a useful understanding of assembly in the modern world you’ll end up learning a bit of both eventually.

That being said, learn whatever your local physical machine uses. That way you’ll get to run the assembly you write on the bare metal of your actual physical sitting-in-front-of-you processor, which is totally awesome and fun.

(Beware, this much fun might cause you to spontaneously grow a grey neckbeard.)

---

<div class="post-metadata">

**Author:** ![AndrewCodeDev](https://ziggit.dev/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@AndrewCodeDev](https://ziggit.dev/u/AndrewCodeDev)\
**Post date:** [May 15, 2024, 2:38pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/3 "2024-05-15T14:38:21Z")

</div>

> [@neurocyte](#):
>
> (Beware, this much fun might cause you to spontaneously grow a grey neckbeard.)

Average assembly enjoyer:

 ![Gandalf-2](https://ziggit.dev/uploads/default/original/2X/8/8c234c6f83776ad1bd869ec72f2b2f79a7bb208d.webp)

(I agree with @neurocyte’s suggestion).

---

<div class="post-metadata">

**Author:** ![matklad](https://ziggit.dev/user_avatar/ziggit.dev/matklad/32/2462_2.png) [@matklad](https://ziggit.dev/u/matklad)\
**Post date:** [May 15, 2024, 2:53pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/4 "2024-05-15T14:53:49Z")

</div>

> [@AndrewCodeDev](#):
>
> Average assembly enjoyer:

Typical staff engineer I would say

> If so should I learn this dying x86 or rising star arm? I work on m1 mac.

I’d suggest:

- learn RISC-V as a clean, reasonable example of an understandable CPU arch
- learn about intel sytnax vs AT&T sytnax, this is MAJOR stupid gotcha
- pickup bits of x86 and ARM as you go/as you need them

---

<div class="post-metadata">

**Author:** ![bortzmeyer](https://ziggit.dev/letter_avatar_proxy/v4/letter/b/c0e974/32.png) [@bortzmeyer](https://ziggit.dev/u/bortzmeyer)\
**Post date:** [May 15, 2024, 4:11pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/5 "2024-05-15T16:11:53Z")

</div>

RISC-V [RISC-V - Wikipedia](https://en.wikipedia.org/wiki/RISC-V) Simple, free instruction set. Can be produced from Zig.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [May 15, 2024, 4:40pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/6 "2024-05-15T16:40:20Z")

</div>

I find that the best way to learn assembly is by reverse engineering. This is equivalent to learning to program by reading other people’s code. It’s an incredibly useful skill to have, and literally every program is available for you to reverse engineer. There is more material on reverse engineering for x86, and also more programs. Even in Apple silicon, I believe most programs are still x86, being run by Apple’s builtin emulator. I recommend [R4ndom’s](https://legend.octopuslabs.io/sample-page.html) tutorial, which is for x86.

---

<div class="post-metadata">

**Author:** ![chung-leong](https://ziggit.dev/user_avatar/ziggit.dev/chung-leong/32/999_2.png) [@chung-leong](https://ziggit.dev/u/chung-leong)\
**Post date:** [May 15, 2024, 5:10pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/7 "2024-05-15T17:10:12Z")

</div>

WASM is a good introduction to assembly, I think.

[https://webassembly.github.io/spec/core/appendix/index-instructions.html](https://webassembly.github.io/spec/core/appendix/index-instructions.html)

---

<div class="post-metadata">

**Author:** ![chrboesch](https://ziggit.dev/user_avatar/ziggit.dev/chrboesch/32/438_2.png) [@chrboesch](https://ziggit.dev/u/chrboesch)\
**Post date:** [May 15, 2024, 5:49pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/8 "2024-05-15T17:49:43Z")

</div>

As an old guy who started programming with assembly language, I always advise learning this. You will gain a better and deeper understanding of how a computer works. But which one is difficult to say. I think after a while you’ll know what interests you. To get started, I would normally recommend [flat assembler](https://flatassembler.net/). But it probably doesn’t run on the Mac so I can’t give a recommendation. Except definitely try. 👍 😄

---

<div class="post-metadata">

**Author:** ![permutationlock](https://ziggit.dev/user_avatar/ziggit.dev/permutationlock/32/9958_2.png) [@permutationlock](https://ziggit.dev/u/permutationlock)\
**Post date:** [May 15, 2024, 7:38pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/9 "2024-05-15T19:38:41Z")

</div>

Full reverse engineering is probably a better exercise, but it’s also good to just read and understand the assembly output for programs you know the source for.

I have enjoyed playing around with the [QBE](https://c9x.me/compile/) code generation backend recently. QBE uses a simple intermediate representation and generates very nice readable assembly in my opinion. The only downside is that for x86 output it uses AT&T syntax, but the syntax differences are easy to get used to IMO.

If you know C then [cproc](https://sr.ht/~mcf/cproc/) is a nice C11 compiler that uses QBE for code generation. A nice things about QBE and cproc is that their source code is also fairly small and readable\[1\].

I don’t have an Apple computer, but at first glance it seems that QBE has `amd64_apple` and `arm64_apple` targets.

* * *

1. The variable names used in QBE’s source may stretch some people’s definition of readable.

---

<div class="post-metadata">

**Author:** ![dude\_the\_builder](https://ziggit.dev/user_avatar/ziggit.dev/dude_the_builder/32/557_2.png) [@dude\_the\_builder](https://ziggit.dev/u/dude_the_builder)\
**Post date:** [May 15, 2024, 9:41pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/10 "2024-05-15T21:41:06Z")

</div>

> [@chrboesch](#):
>
> As an old guy who started programming with assembly

What happened to your grey neckbeard? 😹

---

<div class="post-metadata">

**Author:** ![chrboesch](https://ziggit.dev/user_avatar/ziggit.dev/chrboesch/32/438_2.png) [@chrboesch](https://ziggit.dev/u/chrboesch)\
**Post date:** [May 15, 2024, 10:24pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/11 "2024-05-15T22:24:58Z")

</div>

Shaved off, makes me look old. 🤣

---

<div class="post-metadata">

**Author:** ![gonzo](https://ziggit.dev/user_avatar/ziggit.dev/gonzo/32/54_2.png) [@gonzo](https://ziggit.dev/u/gonzo)\
**Post date:** [May 16, 2024, 8:27am UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/12 "2024-05-16T08:27:54Z")

</div>

Yeah, mine quickly turned from black to grey, then to white. My wife says it gives me a “distinguished” look – I guess that’s just another word for “old” 🙂 .

---

<div class="post-metadata">

**Author:** ![Validark](https://ziggit.dev/user_avatar/ziggit.dev/validark/32/646_2.png) [@Validark](https://ziggit.dev/u/Validark)\
**Post date:** [May 16, 2024, 11:42am UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/13 "2024-05-16T11:42:03Z")

</div>

Just do it. Why spend time debating which one to learn? It’s not like if you learn x86 it will permanently ruin your ability to learn anything else. Just start on what interests you.

---

<div class="post-metadata">

**Author:** ![mscott9437](https://ziggit.dev/user_avatar/ziggit.dev/mscott9437/32/574_2.png) [@mscott9437](https://ziggit.dev/u/mscott9437)\
**Post date:** [May 16, 2024, 11:57am UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/14 "2024-05-16T11:57:49Z")

</div>

MASM is worth looking into, especially if youre into Win32 programming.

---

<div class="post-metadata">

**Author:** ![chung-leong](https://ziggit.dev/user_avatar/ziggit.dev/chung-leong/32/999_2.png) [@chung-leong](https://ziggit.dev/u/chung-leong)\
**Post date:** [May 16, 2024, 1:03pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/15 "2024-05-16T13:03:30Z")

</div>

> [@Validark](#):
>
> Just do it. Why spend time debating which one to learn? It’s not like if you learn x86 it will permanently ruin your ability to learn anything else. Just start on what interests you.

The question is not entirely irrelevant, since x86 is CISC while ARM is RISC. The latter should in theory be easier to understand.

---

<div class="post-metadata">

**Author:** ![Validark](https://ziggit.dev/user_avatar/ziggit.dev/validark/32/646_2.png) [@Validark](https://ziggit.dev/u/Validark)\
**Post date:** [May 16, 2024, 1:31pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/16 "2024-05-16T13:31:08Z")

</div>

RISC vs CISC is not a meaningful distinction. No ISA today is meant for a small and simple in-order machine unless it’s meant to go in your thermometer.

ARM has BSL, BIF, and BIT. These are all the same ternary conditional, but with the arguments in a different order, so that the destination register is different. I don’t know what “RISC” means to you but this definitely does not qualify.

And there is no difference in ease of understanding between ARM and x86. Actually, if I had to pick, I’d say ARM is probably more difficult. x86 is straightforward and just has a lot of facilities that make sense and there is a blessed way to accomplish most things you’d want to do. ARM is a bit more… creative.

---

<div class="post-metadata">

**Author:** ![Eisenhauer](https://ziggit.dev/letter_avatar_proxy/v4/letter/e/76d3ee/32.png) [@Eisenhauer](https://ziggit.dev/u/Eisenhauer)\
**Post date:** [May 16, 2024, 2:34pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/17 "2024-05-16T14:34:55Z")

</div>

I suggest to start with whatever your Machine uses.

It is that assembly you get to see, if you run your programs in debuggers or profilers.

I love to play with small examples on [Compiler Explorer](https://godbolt.org/). It gives easy access to documentation of the used assembly instructions. Just remember to use zigs cross compilation capabilities and add your target, like [`-target arm-macos`](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:zig,selection:(endColumn:1,endLineNumber:5,positionColumn:1,positionLineNumber:5,selectionStartColumn:1,selectionStartLineNumber:5,startColumn:1,startLineNumber:5),source:'//+Type+your+code+here,+or+load+an+example.%0Aexport+fn+square(num:+i32)+i32+%7B%0A++++return+num+*+num%3B%0A%7D%0A'),l:'5',n:'1',o:'Zig+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:z0120,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:zig,libs:!(),options:'-target+arm-macos',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+zig+0.12.0+(Editor+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

---

<div class="post-metadata">

**Author:** ![nyc](https://ziggit.dev/user_avatar/ziggit.dev/nyc/32/1167_2.png) [@nyc](https://ziggit.dev/u/nyc)\
**Post date:** [May 17, 2024, 11:06pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/18 "2024-05-17T23:06:38Z")

</div>

The only RISC-like instruction set I know of is the x86 uops lol.

---

<div class="post-metadata">

**Author:** ![matklad](https://ziggit.dev/user_avatar/ziggit.dev/matklad/32/2462_2.png) [@matklad](https://ziggit.dev/u/matklad)\
**Post date:** [May 17, 2024, 11:32pm UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/19 "2024-05-17T23:32:18Z")

</div>

As we edging closer to “what is RISC” definitions war, obligatory link: [What is RISC?](https://danluu.com/risc-definition/)

---

<div class="post-metadata">

**Author:** ![raddari](https://ziggit.dev/user_avatar/ziggit.dev/raddari/32/991_2.png) [@raddari](https://ziggit.dev/u/raddari)\
**Post date:** [May 18, 2024, 8:09am UTC](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328/20 "2024-05-18T08:09:59Z")

</div>

A few weeks ago I decided to learn some x86-64 assembly just for fun, and I wanted to see if I could utilise the zig build system to make linking and testing easy. As it turns out, zig does in fact make it very easy to create a static library out of your assembly code, and write tests in zig which link to that static library!

Overall I would definitely recommend diving into assembly, it was very eye opening (and fun!) for me. Just pick a flavour that works natively on your machine and go for it 😁

I’ll leave a link to my project here since you (and anyone else that stumbles across it) might find it helpful to see an example of invoking nasm and running tests using build.zig.

> **[zig-nasm-lib](https://codeberg.org/raddari/zig-nasm-lib)**
>
> An x86-64 assembly library utilising the zig build system for invoking \`nasm\` and testing.

[Next page](https://ziggit.dev/t/i-want-to-learn-assembler-do-i-if-so-x86-or-arm/4328.md?page=2)
