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:
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.
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.
name DD value
DD (Define Double Word) is used to define a 32-bit unsigned variable.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).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.
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.
name DD value
DD (Define Double Word) is also used to define a signed 32-bit variable.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.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) |
Use DWORD (unsigned):
Use SDWORD (signed):
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.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.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.| 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). |
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.
Open this section to load past papers