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›Defining DWORD and SDWORD Data
    Computer Organization and Assembly LanguageTopic 50 of 73

    Defining DWORD and SDWORD Data

    6 minread
    1,057words
    Intermediatelevel

    DWORD and SDWORD Data in Assembly Language

    In assembly language, DWORD and SDWORD are data types used to represent 32-bit values. Both terms are commonly used in assembly languages like MASM (Microsoft Macro Assembler) and NASM (Netwide Assembler) to store larger integer values. The difference between them lies in how the data is treated — specifically, whether the data is signed or unsigned.

    Here’s an in-depth look at each of these data types:


    1. DWORD (Unsigned Double Word)

    The DWORD data type represents an unsigned 32-bit integer, meaning it can store only non-negative values. A DWORD consists of 4 bytes (32 bits), and it is used when you need to store integer values that are always positive or zero.

    Range of DWORD:

    • 0 to 4,294,967,295 (in decimal)
    • 0x00000000 to 0xFFFFFFFF (in hexadecimal)

    In DWORD (unsigned), all 32 bits are used to represent the magnitude of the number, with no sign bit. This gives you a large range of positive integers.

    Syntax:

    name DD value
    
    • DD (Define Double Word) is used to define a 32-bit unsigned variable.
    • name: The label or variable name.
    • value: The unsigned value assigned to the DWORD variable (in the range 0 to 4,294,967,295).

    Example: Declaring an Unsigned DWORD

    section .data
        largeValue DD 1234567890     ; Define a 32-bit unsigned DWORD with the value 1234567890
        maxValue DD 4294967295       ; Define a DWORD with the maximum value for an unsigned 32-bit integer (4,294,967,295)
    

    In this example:

    • largeValue holds 1234567890, which is a valid unsigned 32-bit number.
    • maxValue holds 4294967295, which is the maximum value that can be stored in a DWORD (unsigned).

    2. SDWORD (Signed Double Word)

    The SDWORD data type represents a signed 32-bit integer, meaning it can store both positive and negative values. A SDWORD consists of 4 bytes (32 bits), and it is used when you need to store values that can be either positive or negative.

    Range of SDWORD:

    • -2,147,483,648 to 2,147,483,647 (in decimal)
    • 0x80000000 to 0x7FFFFFFF (in hexadecimal)

    In SDWORD (signed), one bit (the most significant bit or MSB) is used for the sign (positive or negative). This bit is 0 for positive numbers and 1 for negative numbers. The remaining 31 bits are used to represent the magnitude of the number in two's complement representation.

    Syntax:

    name DD value
    
    • DD (Define Double Word) is also used to define a signed 32-bit variable.
    • name: The label or variable name.
    • value: The signed value assigned to the SDWORD variable (in the range of -2,147,483,648 to 2,147,483,647).

    Example: Declaring a Signed SDWORD

    section .data
        signedValue DD -1234567890    ; Define a 32-bit signed SDWORD with value -1234567890
        maxSignedValue DD 2147483647  ; Define a signed SDWORD with the maximum value for a signed 32-bit integer
        minSignedValue DD -2147483648 ; Define a signed SDWORD with the minimum value for a signed 32-bit integer
    

    In this example:

    • signedValue holds -1234567890, which is a valid negative number for a signed 32-bit integer.
    • maxSignedValue holds 2147483647, the largest positive value for a signed 32-bit integer.
    • minSignedValue holds -2147483648, the smallest (most negative) value for a signed 32-bit integer.

    DWORD vs. SDWORD: Key Differences

    The key difference between DWORD and SDWORD lies in how they handle the values they store:

    Feature DWORD (Unsigned Double Word) SDWORD (Signed Double Word)
    Size 32 bits (4 bytes) 32 bits (4 bytes)
    Range 0 to 4,294,967,295 (decimal) -2,147,483,648 to 2,147,483,647 (decimal)
    Sign Non-negative only (0 to 4,294,967,295) Can represent both positive and negative values
    Use Case For values that are always non-negative (e.g., memory addresses, file sizes) For values that can be negative (e.g., temperatures, signed counters)
    Hexadecimal Range 0x00000000 to 0xFFFFFFFF 0x80000000 to 0x7FFFFFFF (negative), 0x00000000 to 0x7FFFFFFF (positive)

    When to Use DWORD vs. SDWORD

    • Use DWORD (unsigned):

      • When you know that the values will always be non-negative. This could be data like:
        • Memory addresses, where negative numbers don’t make sense.
        • File sizes, where the size of a file is always positive.
        • Array indices, where the index cannot be negative.
        • Pixel values in an image, as pixel intensity values are usually non-negative.
    • Use SDWORD (signed):

      • When you need to store both positive and negative values. This could include:
        • Temperature readings, where the temperature can be both above and below zero.
        • Signed counters or indices, where the count can go negative (e.g., bank balance adjustments).
        • Differences between values, where negative values are possible.

    Examples of Using DWORD and SDWORD

    Example 1: Using DWORD for Unsigned Data

    Let’s say you need to store a large memory address in a program, and you know that addresses are always non-negative:

    section .data
        memoryAddress DD 0x12345678   ; Declare an unsigned DWORD to hold a memory address
    
    • memoryAddress holds the 32-bit unsigned value 0x12345678 (305,419,896 in decimal), which represents a valid memory address.

    Example 2: Using SDWORD for Signed Data

    Now, let’s store a temperature reading that can be both negative and positive:

    section .data
        temperature DD -15            ; Declare a signed SDWORD to hold a temperature value (-15)
        maxTemperature DD 50          ; Declare a signed SDWORD to hold a positive temperature value (50)
    
    • temperature holds the value -15, indicating a temperature below freezing.
    • maxTemperature holds the value 50, which is a positive temperature.

    Example 3: Handling Unsigned and Signed Data Together

    Let’s declare both an unsigned file size and a signed balance:

    section .data
        fileSize DD 4294967295         ; Define an unsigned DWORD for file size (maximum value for DWORD)
        bankBalance DD -500            ; Define a signed SDWORD for bank balance (negative value)
    
    • fileSize holds the maximum value for a 32-bit unsigned integer (4,294,967,295), which represents the file size.
    • bankBalance holds -500, representing a negative bank balance.

    Summary

    Data Type Size Range (Decimal) Use Case
    DWORD 32 bits 0 to 4,294,967,295 Used for non-negative values (e.g., memory addresses, file sizes).
    SDWORD 32 bits -2,147,483,648 to 2,147,483,647 Used for signed values (e.g., temperature, signed counters, bank balances).
    • DWORD is useful when dealing with non-negative data, where you need a large positive range.
    • SDWORD is used when your data can be both positive and negative, and you need to store both types of values.

    Choosing between DWORD and SDWORD depends on the nature of the data you are working with: whether it's always non-negative or can include both negative and positive values.

    Previous topic 49
    WORD and SWORD Data
    Next topic 51
    Knowledge about Different Data Types

    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,057
      Code examples0
      DifficultyIntermediate