Lecture 5 - ASM

Updated 14 Oct 2026

What is Assembly?

  • Assembly language is a very low-level programming language.
  • Instead of high-level statements like "print text" or "store a number", you give the CPU direct instructions: e.g. move this number into this register.
  • This specific code is x86 assembly, written in the style commonly used on Linux.

Analogy Think of assembly like giving someone very literal, step-by-step instructions instead of a general goal — instead of "make me a sandwich," you say "pick up the knife, pick up the bread, cut it in half..."

The Example Code

section .data
    hello: db '1337', 10
section .text
    global _start
_start:
    mov ebx, 1337

Line-by-Line Breakdown

section .data

  • Tells the assembler: the following lines describe data (stored values), not instructions.
  • Think of this as a place where you store constants — like text or numbers — that your program might want to use later.

hello: db '1337', 10

  • This line creates data in memory.

  • hello:

    • This is a label (basically a name).
    • It marks a location in memory so the program can refer to it later.
  • db

    • Means define bytes.
    • You are telling the assembler to store raw bytes in memory.
  • '1337'

    • This is a string. Each character ('1', '3', '3', '7') is stored as a byte.
  • 10

    • This is the ASCII value for a newline character (\n).
  • So what gets stored in memory?

    • 1 3 3 7 \n

    • This is similar to writing in C:

      char hello[] = "1337\n";
  • Important: Nothing prints yet — this line just stores the text.

section .text

  • Tells the assembler: the following lines are executable code (instructions for the CPU).

global _start

  • Says: make _start visible to the operating system.
  • On Linux, _start is the entry point — the place where the OS begins running your program.

Analogy Think of 

_start as the very first line of code that runs — like the opening scene of a movie.

_start:

  • This is a label marking the beginning of the program.
  • When the program starts, the CPU jumps right here.

mov ebx, 1337

  • This is the only actual instruction in the program so far.
  • Breaking it down:
    • mov = move data
    • ebx = a CPU register
    • 1337 = the number being moved
  • Meaning: put the number 1337 into the CPU register called EBX.
  • Recall: a register is a tiny, super-fast storage location inside the CPU itself.

Analogy You can think of 

ebx like a small box the CPU uses to hold a number temporarily.

What Does This Program Actually Do?

  • Stores the text "1337\n" in memory
  • Starts running at _start
  • Puts the number 1337 into register ebx
  • ... then stops

It does not:

  • Print anything
  • Exit properly
  • Use the hello string yet

Summary — This is an example of:

  • How to define data
  • How to define a program entry point
  • How to move a value into a register