DEV Community

Assembly Language for Beginners: Talk to Your Computer in Its Own Language

Every program you have ever run - your browser, your games, your operating system - eventually becomes Assembly language. It is the lowest-level programming language humans still write by hand: a thin, readable layer over the machine code your CPU actually executes.

You probably will not build a web app in Assembly, but learning it teaches you how computers really work: registers, memory, the stack, and why your Python code is slow in some places and fast in others.

Assembly looks intimidating because it has no if statements, no loops, and no variables as you know them. Instead you move values between registers, add them, compare them, and jump to labels.

A tiny program

Here is a tiny x86-64 program that exits with code 42:

section .text
global _start
_start:
    mov rax, 60 ; syscall number for exit
    mov rdi, 42 ; exit code
    syscall

That is the whole program. mov copies a value into a register, and syscall asks the operating system to do something. There is nothing hiding underneath - what you write is almost exactly what the CPU does.

Why learn it

Assembly is a good first low-level language because it removes the mystery. When you learn it, you stop guessing what "the stack" is: you push values onto it and pop them off yourself.

You see why a function call costs something, why a buffer overflow is dangerous, and why a compiler's optimisation matters. It also makes you a better debugger in every other language, because when a program crashes you can read the disassembly instead of staring at it.

How to start

Install NASM and a linker on Linux, or use an online assembler like Compiler Explorer's Assembly view.

Write the exit program above, assemble it with:

nasm -f elf64 hello.asm && ld hello.o -o hello

Run it, and check the exit code with:

echo $?

Then:

  • write a program that prints "Hello" using the write syscall
  • then one that adds two numbers

Each step takes an evening, and each one makes the machine less mysterious.

Who is it for

Students studying computer science, embedded developers, security researchers, and anyone who wants to understand performance deeply. If you only want to build websites, you do not need Assembly - but if you want to know what is really happening when your code runs, there is no better teacher.

The limits

Assembly is slow to write, tied to one CPU architecture, and a 100-line program can take a day. You would never write a web app in it. Treat it as a learning tool and a specialist tool - for bootloaders, drivers, game engines' hot loops, and security research - not as your everyday language.

Your first step today

Install NASM, assemble the exit program above, and get it to return 42. Then change the number, rebuild, and watch it change. You have just written a program with nothing between you and the CPU - and that feeling is worth the effort.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.