Two-File Pattern
Part of the Fundamentals section of Coddy's Assembly journey — lesson 5 of 45.
Throughout this course, you will write every program using two separate files:
| File | Purpose |
|---|---|
data.asm | Stores all data (strings, numbers, variables) |
main.asm | Stores all code (instructions, logic, flow) |
This is not required by the assembler. You could put everything in one file. But separating code from data makes your programs cleaner, easier to read, and easier to debug.
Why two files?
- Organization — Data and code have different purposes. Keeping them separate helps you think clearly.
- Reusability — You can use the same
data.asmwith differentmain.asmfiles.
- Readability — You never have to scroll through long strings to find your code.
- Industry practice — Real projects separate code and data (though often in more complex ways).
How it works:
The main.asm file includes the data.asm file using the %include directive. This tells the assembler: "insert the entire contents of data.asm right here before assembling."
The two files side by side:
| data.asm | main.asm |
|---|---|
section .data | %include "data.asm" |
| (variables go here) | section .text |
global _start | |
_start: | |
| (instructions go here) |
What each section does:
| Section | Purpose | Which file? |
|---|---|---|
section .data | Holds data that exists in memory when the program runs | data.asm |
section .text | Holds the executable instructions (code) | main.asm |
global _start | Makes the entry point visible to the linker | main.asm |
_start: | Label where program execution begins | main.asm |
You do not need to memorize
section .data,section .text,global _start, or_start:right now. We will cover each of these commands in detail in the following lessons. For now, just look at the big picture and understand the structure of the two files.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
1The Machine
What is CPUMemoryRegisters vs MemoryHow instructions workTwo-File PatternThe x86-64 Architecture