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 PortalCOMP3137Defining Dword Sdword …
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 50 of 73
    Topic Study Note Illustration
    50

    Defining DWORD and SDWORD Data

    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...

    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 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