Recap: Build data.asm
Part of the Fundamentals section of Coddy's Assembly journey — lesson 30 of 45.
Challenge
You have learned several ways to define data in the .data section:
| Lesson | What you learned |
|---|---|
| 3.1 | The .data section — where data goes |
| 3.2 | db — Define Byte (1 byte) |
| 3.3 | dw — Define Word (2 bytes) |
| 3.4 | dd — Define Double Word (4 bytes) |
| 3.5 | dq — Define Quad Word (8 bytes) |
| 3.6 | Strings with db — creating text |
| 3.7 | The $ symbol — calculating string lengths automatically |
Now it is time to put everything together and build a complete data.asm file.
What you will create in this challenge:
A data.asm file that contains:
- A string with automatic length calculation
- A byte value
- A word value
- A double word value
- A quad word value
All properly organized in the .data section.
Example of a complete <strong>data.asm</strong>:
section .data
; String with automatic length
msg db 'Hello', 0x0a
msgLen equ $ - msg
; Numbers of different sizes
smallNum db 100
mediumNum dw 5000
largeNum dd 100000
veryLarge dq 5000000000Why this matters:
In the next chapters, you will use data.asm files like this to store the data your programs need. The main.asm file will include your data.asm and use the labels and lengths you have defined.
Challenge
Create a complete data.asm file with the following:
- A string called
welcomewith the value 'Welcome!' followed by a newline (0x0a) - A constant called
welcomeLenthat calculates the length automatically using$ - welcome - A byte called
scorewith the value 99 - A word called
yearwith the value 2025 - A double word called
populationwith the value 8500000 - A quad word called
starswith the value 100000000000
All inside the .data section.
Try it yourself
%include "data.asm"
section .text
global _start
_start:
; Print the welcome string
mov rax, 1
mov rdi, 1
mov rsi, welcome
mov rdx, welcomeLen
syscall
; Exit
mov rax, 60
mov rdi, 0
syscallAll lessons in Fundamentals
1The Machine
What is CPUMemoryRegisters vs MemoryHow instructions workTwo-File PatternThe x86-64 Architecture4Data Definition
The .data Sectiondb - Define Bytedw - Define Worddd - Define Double Worddq - Define Quad WordStrings with dbThe $ SymbolRecap: Build data.asm