Menu
Coddy logo textTech

db - Define Byte

Part of the Fundamentals section of Coddy's Assembly journey — lesson 24 of 45.

The most basic way to create data in memory is dbDefine Byte. It creates one byte (8 bits) of data.

Syntax:

label db value
  • label — the name you give to this memory address
  • db — Define Byte directive
  • value — the number or character to store (0 to 255)

Examples:

section .data
    age db 25          ; Creates a byte called "age" containing 25
    grade db 'A'       ; Creates a byte called "grade" containing 65 (ASCII for 'A')
    zero db 0          ; Creates a byte called "zero" containing 0

What you can store in one byte:

TypeRangeExample
Small number0 to 255db 100
Character'A' to 'z'db 'X'
ASCII code0 to 255db 65 (same as 'A')

Multiple bytes on one line:

You can define several bytes in a row using commas:

section .data
    numbers db 5, 10, 15, 20    ; Creates 4 bytes: 5, 10, 15, 20
    letters db 'A', 'B', 'C'    ; Creates 3 bytes: 65, 66, 67

How to use a byte in your code:

section .data
    myByte db 42

section .text
    mov al, [myByte]    ; Load the value 42 into al
    add al, 1           ; al becomes 43
    mov [myByte], al    ; Store 43 back into myByte

Important rule:

RuleExplanation
Value must fit in 1 byte0 to 255 (or a single character)
Use al to load or storeal is the 8-bit register for bytes

Common mistake:

; Wrong: trying to store a number too large for a byte
section .data
    error db 300    ; 300 is too big (max 255)
challenge icon

Challenge

Easy

Create a byte called score with the value 15 in the .data section.

Write the data.asm file with the correct .data section and the db directive.

Try it yourself

%include "data.asm"

section .text
    global _start

_start:
    mov al, [score]
    
    mov r12, rax
    
    add al, 48
    mov [digit], al
    
    mov rax, 1
    mov rdi, 1
    mov rsi, digit
    mov rdx, 1
    syscall
    
    mov rax, 60
    mov rdi, 0
    syscall

section .bss
    digit resb 1
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals