Assembler basics: what assembly language is and where it is used
About assembly language
Assembly language is the human-readable form of machine code: one
instruction per CPU operation, no runtime, nothing hidden. An
assembler turns the source into an object
file, and a linker turns the object file into an executable. This site
teaches it on x86-64 Linux with NASM, from registers
and syscalls up to SIMD, sockets, and a boot sector.
Every instruction moves data, does arithmetic, or changes the flow of
control, and each one maps almost one-to-one to a CPU instruction. The
program has no garbage collector and no hidden work: what you write is
what the CPU runs.
Where it is used
Assembly runs everywhere a program runs: Linux,
Windows, macOS, and the embedded devices around you.
It is at the bottom of every operating system kernel, bootloader and
firmware, and compilers emit it for the hot parts of C and
C++ programs.
You will not write a web application in assembly, but you will read it
when a compiler emits a surprising instruction, when you patch a binary,
when you debug a crash without source, or when you write a boot sector.
The 50-lesson course takes you from
the first program to those jobs.
Hello world
The classic first program writes one line to the screen and exits with two Linux system calls: sys_write (number 1) and sys_exit (number 60). Save it as hello.asm:
section .data
msg db "Hello from assembly", 10
len equ $ - msg
section .text
global _start
_start:
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, msg ; buffer
mov rdx, len ; count
syscall
mov rax, 60 ; sys_exit
xor rdi, rdi ; status 0
syscall
Assemble it to a 64-bit ELF object, then link the object into an executable:
nasm -f elf64 -o hello.o hello.asm
ld -o hello hello.o
Run the executable:
./hello
Hello from assembly
The program writes the 20 bytes of the string plus the newline and exits with status 0. That is the whole shape of the course: registers carry the arguments, and a syscall does the work.
Article author: Arthur Isaev