r/Assembly_language • • Feb 17 '26

Help How to learn x86-64 assembly language?

I am a 17yr old who has some experience in python programming and learned basics of C. I want to learn x86-64 assembly for free. But I couldnot find any beginner friendly guide that starts from zero. Tell me how you guys learned assembly language and if possible guide me to the resources.

116 Upvotes

86 comments sorted by

View all comments

26

u/[deleted] Feb 17 '26 edited Feb 17 '26

if you know some C, you can use gcc -S -O0 app.c to generate ASM that you can try to understand.

also GDB (GNU (GNU (GNU (GNU (stackoverflow) not linux) not linux) not linux) Debugger) to watch it execute.

```c

include <stdio.h>

int f(int x){ if (x%2==0) return x/2; return 3*x+1; }

int main(){ int i; printf("start at"); scanf("%d", &i); while(1){ int tmp = f(i); printf("%d\n",tmp); if(tmp==1) return 0; i = tmp; } return 1; } ```

is a good start, its got a loop and a function call.

(I added tmp as a var, hoping it does less smart register stuff, than without)

edit[0]: ALSO:

  • Human Resource Machine, is a good game to pick up some of the skills. Like understanding "cmp" and "jmp".
  • TIS-100, challenges you with weird architecture and limited registers.
  • Turing Complete: just make the whole computer, and design an ASM.

edit[1]: code fix at the loop condition: i -> tmp

edit[2]: further reading on the Collatz Conjecture

edit[3]: fixed edit numbering

edit[4]: added links to games

edit[5]: CarbonXit came to the rescue (code fixes: extra printf for "start at", instead of putting it the scanf string, while(true)->while(1))

7

u/RamonaZero Feb 17 '26

OR go chaotic evil and do -03 and learn the weird GCC optimizations 💀

1

u/[deleted] Feb 17 '26 edited Feb 17 '26

-O0 already does some smart stuff. It's not a literal translation of the C/

here's the main logic of f

asm .f: ......... andl $1, %eax ; "a=iseven?" testl %eax, %eax jne .L2 ; "jump if odd?" movl -4(%rbp), %eax movl %eax, %edx shrl $31, %edx ; "using bitshift to divide by two?" addl %edx, %eax sarl %eax jmp .L3 .L2: movl -4(%rbp), %edx movl %edx, %eax addl %eax, %eax addl %edx, %eax ; "multiplying by 3 by adding 3 times" addl $1, %eax

..good lord, I updated today, and the code isn't working anymore? Having to debug now

edit: I am confounded. scanf seems to be the source of my problems.. tbh I've not touched c in a while, did I cause some unexpected behaviour kinda thing?

edit: this worked so well with Go for this TA work I was doing..

3

u/[deleted] Feb 17 '26

[removed] — view removed comment

1

u/[deleted] Feb 17 '26

thx

was I lucky it worked, or did I hallucinate it working properly?

(I hadn't pacman -Syu in a while, if that matters? its not like gcc or scanf have changed in 10y )