Menu
Coddy logo textTech

dd - Define Double Word

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

dw creates 2 bytes of data. But sometimes you need even larger numbers. For that, you use ddDefine Double Word.

A double word in x86 assembly is 4 bytes (32 bits).

Syntax:

label dd value

Examples:

section .data
    myNumber dd 50000        ; 4 bytes, value 50000
    bigNum   dd 4000000      ; 4 bytes, value 4 million
    max32    dd 4294967295   ; Maximum 32-bit value

Comparison table:

DirectiveSizeRangeRegister to use
db1 byte0 to 255al
dw2 bytes0 to 65,535ax
dd4 bytes0 to 4,294,967,295eax

How to use a double word in your code:

section .data
    myNumber dd 50000

section .text
    mov eax, [myNumber]    ; Load value into eax
    add eax, 10000         ; eax becomes 60000
    mov [myNumber], eax    ; Store back

Important rule:

RuleExplanation
Use eax to load or storeeax is the 32-bit register
challenge icon

Challenge

Easy

Create a double word called distance with the value 125000 in the .data section.

Try it yourself

%include "data.asm"

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

section .bss
    buffer resb 32

section .text
    global _start

_start:
    ; Load the double word value into eax
    mov eax, [distance]
    
    ; Convert eax to decimal string
    mov rsi, buffer
    add rsi, 31          ; Go to end of buffer
    mov byte [rsi], 0    ; Null terminator
    
    mov ecx, 10          ; Divisor for decimal conversion

convert_loop:
    xor edx, edx         ; Clear edx for division
    div ecx              ; Divide eax by 10, eax = quotient, edx = remainder
    add dl, '0'          ; Convert remainder to ASCII
    dec rsi
    mov [rsi], dl        ; Store digit
    cmp eax, 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, 31
    sub r9, rsi          ; r9 = number of digits
    
    ; Print message
    mov rax, 1
    mov rdi, 1
    mov rdx, msg_len
    mov rsi, msg
    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