ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Data Definition Statem…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    6 min read
    Topic 47 of 73
    Topic Study Note Illustration
    47

    Data Definition Statement

    In assembly language, data definition statements are used to declare and initialize variables, constants, and data structures that will be used by the program. These statements define...

    Data Definition Statements in Assembly Language

    In assembly language, data definition statements are used to declare and initialize variables, constants, and data structures that will be used by the program. These statements define the type and size of the data, allocate memory, and may also assign initial values to the data items.

    Each assembly language has specific syntax and directives for defining data, but they typically follow similar conventions. The most common data definition directives are:

    • DB (Define Byte)
    • DW (Define Word)
    • DD (Define Double Word)
    • DQ (Define Quad Word)
    • DT (Define Ten Bytes, used for floating-point numbers)
    • RESB, RESW, RESD, RESQ (Reserved space)

    These directives are used in the data section (or .data segment) of a program, which is typically used to store variables, constants, strings, and other data that your program will manipulate.


    1. DB (Define Byte)

    The DB directive is used to define a byte (8 bits) of data. A byte is the smallest unit of storage and can hold values from 0 to 255.

    Syntax:

    name DB value
    
    • name: The label or variable name that will refer to this byte in the program.
    • value: The value assigned to the byte (can be a numeric constant, ASCII character, or other byte-sized value).

    Example:

    section .data
        var1 DB 100    ; Declare a byte variable named 'var1' and initialize it with 100
        var2 DB 'A'    ; Declare a byte variable 'var2' and initialize it with ASCII code of 'A' (65)
    
    • var1 holds the value 100 (which is an integer value).
    • var2 holds the value 'A', which is the ASCII value 65.

    You can also define multiple bytes with a single DB statement:

    section .data
        byte_array DB 1, 2, 3, 4, 5   ; Define an array of 5 bytes
    

    2. DW (Define Word)

    The DW directive is used to define a word (16 bits, or 2 bytes) of data. This is used when you want to store a value that is 2 bytes in size, such as integers in the range of -32,768 to 32,767.

    Syntax:

    name DW value
    

    Example:

    section .data
        word1 DW 1234   ; Define a 16-bit word variable with the value 1234
        word2 DW 10000  ; Define a word variable with the value 10000
    
    • word1 and word2 are both 2-byte variables.

    You can also define multiple words:

    section .data
        word_array DW 1, 2, 3, 4  ; Define an array of 4 words
    

    3. DD (Define Double Word)

    The DD directive is used to define a double word (32 bits, or 4 bytes) of data. Double words are used for larger integer values (up to 4 bytes) and are commonly used in modern 32-bit systems.

    Syntax:

    name DD value
    

    Example:

    section .data
        dword1 DD 1234567890   ; Define a 32-bit double word variable
        dword2 DD -1000        ; Define a 32-bit double word variable with value -1000
    
    • dword1 and dword2 are 4-byte variables.

    You can also define multiple double words:

    section .data
        dword_array DD 100, 200, 300, 400   ; Define an array of 4 double words
    

    4. DQ (Define Quad Word)

    The DQ directive is used to define a quad word (64 bits, or 8 bytes) of data. Quad words are useful for storing larger integer values, typically used in 64-bit systems.

    Syntax:

    name DQ value
    

    Example:

    section .data
        qword1 DQ 1234567890123456   ; Define a 64-bit quad word variable
        qword2 DQ -9876543210       ; Define a 64-bit quad word variable with negative value
    
    • qword1 and qword2 are 8-byte variables.

    5. DT (Define Ten Bytes)

    The DT directive is used for defining a 10-byte (80-bit) data item. This is primarily used to store floating-point numbers (especially extended precision) in some systems.

    Syntax:

    name DT value
    

    Example:

    section .data
        pi DT 3.1415926535   ; Define an 80-bit floating-point number
    
    • pi is a 10-byte floating-point value representing π.

    6. RESB, RESW, RESD, RESQ (Reserved Space)

    These directives are used when you want to reserve memory space but do not want to initialize it immediately. These directives are especially useful for declaring space for variables whose values will be assigned during runtime.

    Syntax:

    name RESB number_of_bytes   ; Reserve 'number_of_bytes' space (1 byte)
    name RESW number_of_words   ; Reserve 'number_of_words' space (2 bytes each)
    name RESD number_of_dwords  ; Reserve 'number_of_dwords' space (4 bytes each)
    name RESQ number_of_qwords  ; Reserve 'number_of_qwords' space (8 bytes each)
    

    Examples:

    section .bss
        buffer RESB 256   ; Reserve 256 bytes (for a buffer or array)
        array RESW 10     ; Reserve space for 10 words (20 bytes)
        data RESD 5       ; Reserve space for 5 double words (20 bytes)
        large_data RESQ 3 ; Reserve space for 3 quad words (24 bytes)
    
    • The .bss section is used to declare uninitialized variables. The space is reserved but not initialized with any values.

    7. Strings and Text Constants

    In assembly, strings and text constants are typically defined using the DB directive, since each character is stored as a byte (8 bits). You can define strings using single or double quotes. A null-terminated string (with an explicit zero at the end) is often used for string handling in many systems.

    Syntax:

    name DB 'string', 0   ; Null-terminated string
    

    Example:

    section .data
        greeting DB 'Hello, World!', 0   ; Null-terminated string
        message DB 'This is a test.', 0
    
    • greeting and message are string constants, terminated by a null byte (0).

    8. Example of Using Data Definition Statements

    section .data
        var1 DB 100        ; A byte variable initialized to 100
        var2 DW 500        ; A word variable initialized to 500
        var3 DD 1000       ; A double word variable initialized to 1000
        var4 DQ 1234567890 ; A quad word variable initialized to 1234567890
        buffer RESB 128    ; Reserve 128 bytes for a buffer
    
    section .text
        ; Assembly code here that will use these variables
    

    Key Points to Remember:

    • DB, DW, DD, and DQ are used to define data of various sizes (byte, word, double word, quad word).
    • The .data section is used to store initialized data.
    • The .bss section is used to reserve space for variables that will be initialized later.
    • You can define constants, variables, arrays, and strings using these data definition statements.
    • RESB, RESW, RESD, and RESQ are used to reserve memory space without initializing it.

    These data definition statements are essential for structuring your program's memory and preparing data for processing by your assembly instructions.

    ← Previous topic 46
    Moving Data from Variable to Register
    Next topic 48 →
    BYTE and SBYTE Data

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language