Skip to content

Assembly Guide — What is Assembly? CPU Architecture and Machine Code

DodaTech Updated 2026-06-28 4 min read

In this tutorial, you will learn about Assembly Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Assembly language is the lowest-level human-readable programming language -- a direct mnemonic representation of the machine instructions that a CPU executes, giving you complete control over hardware without needing to write raw binary.

What You'll Learn

  • What assembly language is and why it matters
  • CPU architecture basics (registers, memory, instructions)
  • x86-64 vs ARM architecture
  • Tools: NASM, GDB, objdump

Why It Matters

Assembly is the language of reverse engineering, malware analysis, operating systems, embedded firmware, and performance-critical code. Durga Antivirus Pro uses assembly-level signature detection to identify malware patterns that higher-level scanners miss. Understanding assembly makes you a better C programmer.

Real-World Use

Security researchers disassemble malware to understand its behavior. Compiler engineers debug Code Generation. Game developers optimize hot paths. Embedded developers write bootloaders and drivers in assembly.

flowchart LR
    A["What is Assembly?"] --> B["x86-64"]
    B --> C["Registers"]
    C --> D["Addressing"]
    D --> E["Instructions"]
    A:::current --> B
    style A fill:#2563eb,stroke:#2563eb,color:#fff
    style B fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style C fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style D fill:#dbeafe,stroke:#2563eb,color:#1e40af
    style E fill:#f1f5f9,stroke:#94a3b8,color:#64748b

What is Assembly?

Assembly language maps directly to CPU instructions. Each assembly instruction corresponds to one machine code instruction. This means:

  • You control exactly what the CPU does
  • No compiler optimizations (you're the compiler)
  • Full access to all CPU features
  • Maximum performance potential
; Assembly: human-readable
mov rax, 42

; Machine code: bytes
; 48 C7 C0 2A 00 00 00

CPU Architecture

A CPU has three main components visible to assembly programmers:

Registers: Fastest memory, inside the CPU. x86-64 has 16 general-purpose registers (RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, R8-R15).

Memory: RAM, accessed via addresses. Assembly reads/writes memory with load and store instructions.

Instructions: Operations the CPU performs (arithmetic, data movement, control flow).

Your First Assembly Program

; hello.asm
section .data
    msg db 'Hello, Assembly!', 0xa
    len equ $ - msg

section .text
    global _start

_start:
    mov rax, 1        ; syscall: write
    mov rdi, 1        ; fd: stdout
    mov rsi, msg      ; buffer
    mov rdx, len      ; length
    syscall

    mov rax, 60       ; syscall: exit
    xor rdi, rdi      ; exit code 0
    syscall
nasm -f elf64 hello.asm -o hello.o
ld hello.o -o hello
./hello

x86-64 vs ARM

Aspect x86-64 ARM64
Registers 16 GP registers 31 GP registers
Memory Can operate on memory directly Load-store (only ldr/str)
Instructions Variable length (1-15 bytes) Fixed 4 bytes
Complexity Complex (CISC) Simple (RISC)
Common in Desktops, servers Mobile, embedded

Common Mistakes

1. Forgetting operand order

NASM: mov dest, src. GAS/AT&T: mov src, dest. Mixing them up is the most common bug.

2. Not preserving callee-saved registers

RBX, RBP, R12-R15 must be saved before use and restored before return.

3. Using 32-bit registers for addresses

mov eax, [address] zero-extends to 64 bits. Use mov rax for 64-bit addresses.

4. Mismatched call/ret

Every call needs a matching ret. Unbalanced pushes cause ret to jump to wrong addresses.

Practice Questions

1. What is the difference between mov rax, [rbx] and mov rax, rbx? First loads the VALUE AT the address in RBX (memory access). Second copies the VALUE in RBX to RAX (register-to-register).

2. Why does the stack grow downward? Historical convention. The heap grows upward from the data segment. Both grow toward each other for efficient memory use.

3. What is a calling convention? Rules for passing arguments, return values, and saving registers between function calls.

Challenge: Write a simple assembly program that adds two numbers and exits with the sum as the exit code.

FAQ

{{< faq question="Do I need to learn assembly today?" >}} For most developers, no -- compilers generate excellent assembly. For security, reverse engineering, embedded, or performance engineering, assembly is essential. {{< /faq >}}

{{< faq question="Which assembly should I learn first?" >}} x86-64 is most widely used (desktops, servers) with the best tooling. ARM is more common in mobile/embedded. Start with x86-64. {{< /faq >}}

{{< faq question="Is NASM or GAS better for beginners?" >}} NASM's Intel syntax is more readable (mov rax, 42 vs movq $42, %rax) and has better error messages. {{< /faq >}}

{{< faq question="How does C code become assembly?" >}} Through preprocessing, Parsing, optimization, and code generation. Run gcc -S file.c to see the generated assembly. {{< /faq >}}

{{< faq question="Can I write a whole program in assembly?" >}} Yes, for bootloaders, OS kernels, embedded firmware, and demoscene productions. For most apps, use a higher-level language with assembly only in hot paths. {{< /faq >}}

What's Next

Now that you understand what assembly is, proceed to learn about x86-64 architecture and registers.

Topic Description Link
x86-64 Architecture and registers {{< ref "02-x86-64" >}}
Registers General purpose and special {{< ref "03-registers" >}}
C See how C maps to assembly C

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro