ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Data Definition Statement
    Computer Organization and Assembly LanguageTopic 47 of 73

    Data Definition Statement

    6 minread
    1,067words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time6 min
      Word count1,067
      Code examples0
      DifficultyIntermediate