Menu
Coddy logo textTech

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:

FilePurpose
data.asmStores all data (strings, numbers, variables)
main.asmStores 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.asm with different main.asm files.
  • 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.asmmain.asm
section .data%include "data.asm"
(variables go here)section .text
 global _start
 _start:
 (instructions go here)

What each section does:

SectionPurposeWhich file?
section .dataHolds data that exists in memory when the program runsdata.asm
section .textHolds the executable instructions (code)main.asm
global _startMakes the entry point visible to the linkermain.asm
_start:Label where program execution beginsmain.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.

quiz iconTest yourself

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

All lessons in Fundamentals