COURSE · 4 LESSONS · 100% FREE

Assembly Language

Talk directly to the CPU. Registers, memory, opcodes. The language beneath all languages.

0Lessons
0Code Examples
ZeroPrerequisites
0%
You've completed 0 of 4 lessons
J/ Next
K/ Prev
Esc Collapse
/ Search
Foundations
01

Hello World (x86-64 Linux)

syscall interface. Registers rax, rdi, rsi, rdx. Linux sys_write and sys_exit.

02

Registers & Data Movement

rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp. mov, lea, push, pop.

section .text
    global _start

_start:
    ; Register operations
    mov rax, 42          ; immediate
    mov rbx, rax         ; register to register
    mov [mem_var], rax   ; register to memory

    ; LEA — Load Effective Address
    lea rdi, [rax + rbx*4 + 10]

    ; Stack operations
    push rax
    push rbx
    pop rcx
    pop rdx

    ; Arithmetic
    add rax, 10          ; rax += 10
    sub rax, 5           ; rax -= 5
    inc rax              ; rax++
    dec rax              ; rax--
    imul rax, 3          ; rax *= 3
    xor rdx, rdx         ; rdx = 0 (fast)
    div rbx              ; rax = rdx:rax / rbx

    ; Exit
    mov rax, 60
    xor rdi, rdi
    syscall

section .data
    mem_var dq 0
03

Control Flow & Comparison

jmp, je, jne, jl, jg. cmp sets flags. Labels are jump targets.

section .text
    global _start

_start:
    mov rax, 42
    cmp rax, 42
    je equal
    jmp not_equal

equal:
    mov rdi, 0
    jmp exit

not_equal:
    mov rdi, 1

exit:
    mov rax, 60
    syscall

; Loop: count from 0 to 9
    xor rcx, rcx
loop_start:
    cmp rcx, 10
    jge loop_end
    ; do something with rcx
    inc rcx
    jmp loop_start
loop_end:
04

Memory & String Operations

Memory addressing modes. rep movsb, rep stosb. System calls for I/O.

section .text
    global _start

_start:
    ; String copy with REP
    mov rsi, src
    mov rdi, dst
    mov rcx, 13
    rep movsb          ; copy RCX bytes from RSI to RDI

    ; Fill memory
    mov rdi, buffer
    mov rcx, 256
    mov al, 0
    rep stosb          ; fill 256 bytes with 0

    ; System call to print
    mov rax, 1         ; sys_write
    mov rdi, 1         ; stdout
    mov rsi, dst
    mov rdx, 13
    syscall

    mov rax, 60
    xor rdi, rdi
    syscall

section .data
    src db 'Hello, World', 0
    dst times 13 db 0
    buffer times 256 db 0