Menu
Coddy logo textTech

Recap: Build data.asm

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

challenge icon

Challenge

You have learned several ways to define data in the .data section:

LessonWhat you learned
3.1The .data section — where data goes
3.2db — Define Byte (1 byte)
3.3dw — Define Word (2 bytes)
3.4dd — Define Double Word (4 bytes)
3.5dq — Define Quad Word (8 bytes)
3.6Strings with db — creating text
3.7The $ 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 5000000000

Why 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:

  1. A string called welcome with the value 'Welcome!' followed by a newline (0x0a)
  2. A constant called welcomeLen that calculates the length automatically using $ - welcome
  3. A byte called score with the value 99
  4. A word called year with the value 2025
  5. A double word called population with the value 8500000
  6. A quad word called stars with 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
    syscall

All lessons in Fundamentals