Menu
Coddy logo textTech

dq - Define Quad Word

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

dd creates 4 bytes of data. But sometimes you need even larger numbers or memory addresses. For that, you use dqDefine Quad Word.

A quad word in x86 assembly is 8 bytes (64 bits).

Syntax:

label dq value

Examples:

section .data
    myNumber dq 10000000000     ; 8 bytes, value 10 billion
    bigNum   dq 123456789012    ; Very large number
    address  dq msg             ; Memory address of label "msg"

Comparison table:

DirectiveSizeRangeRegister to use
db1 byte0 to 255al
dw2 bytes0 to 65,535ax
dd4 bytes0 to 4,294,967,295eax
dq8 bytesVery large (2⁶⁴-1)rax

How to use a quad word in your code:

section .data
    myNumber dq 5000000000

section .text
    mov rax, [myNumber]    ; Load value into rax
    add rax, 1000000000    ; rax becomes 6 billion
    mov [myNumber], rax    ; Store back

Special use: storing addresses

dq is also used to store memory addresses (pointers):

section .data
    message db 'Hello', 0
    pointer dq message      ; Stores the address of message

Important rule:

RuleExplanation
Use rax to load or storerax is the 64-bit register
challenge icon

Challenge

Easy

Create a quad word called universe_age with the value 13800000000 in the .data section.

Try it yourself

%include "data.asm"

section .data
    msg db 'universe_age = '
    msg_len equ $ - msg
    newline db 0xa

section .bss
    buffer resb 64

section .text
    global _start

_start:
    ; Load the quad word value into rax
    mov rax, [universe_age]
    
    ; Convert rax to decimal string
    mov rsi, buffer
    add rsi, 63          ; Go to end of buffer
    mov byte [rsi], 0    ; Null terminator
    
    mov rcx, 10          ; Divisor for decimal conversion

convert_loop:
    xor rdx, rdx         ; Clear rdx for division
    div rcx              ; Divide rax by 10, rax = quotient, rdx = remainder
    add dl, '0'          ; Convert remainder to ASCII
    dec rsi
    mov [rsi], dl        ; Store digit
    cmp rax, 0
    jnz convert_loop

    ; Save digit pointer and length BEFORE they get clobbered
    mov r8, rsi          ; r8 = pointer to first digit
    mov r9, buffer
    add r9, 63
    sub r9, rsi          ; r9 = number of digits
    
    ; Print message
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, msg_len
    syscall
    
    ; Print the number
    mov rax, 1
    mov rdi, 1
    mov rsi, r8
    mov rdx, r9
    syscall
    
    ; Print newline
    mov rax, 1
    mov rdi, 1
    mov rsi, newline
    mov rdx, 1
    syscall
    
    ; Exit
    mov rax, 60
    mov rdi, 0
    syscall
quiz iconTest yourself

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

All lessons in Fundamentals