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 PortalCOMP3137Word Sword Data
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 49 of 73
    Topic Study Note Illustration
    49

    WORD and SWORD Data

    In assembly language, WORD and SWORD refer to data types that store 16-bit values . These types differ in how they handle signed and unsigned values. Let's...

    WORD and SWORD Data in Assembly Language

    In assembly language, WORD and SWORD refer to data types that store 16-bit values. These types differ in how they handle signed and unsigned values. Let's break down the concepts of WORD and SWORD, their ranges, and how they're used in assembly programming.


    1. WORD (Unsigned Word)

    The WORD data type represents a 16-bit unsigned integer, meaning it can store values in the range of 0 to 65535. A word consists of 2 bytes (16 bits), and it is used for storing unsigned values—those that are always non-negative.

    Range of WORD:

    • 0 to 65535 (in decimal)
    • 0000 to FFFF (in hexadecimal)

    Since WORD is unsigned, it doesn't have any sign bit, so all 16 bits are used to represent the magnitude of the number.

    Syntax:

    name DW value
    
    • DW (Define Word) is used to define a 16-bit word variable.
    • name: The label or variable name.
    • value: The unsigned value assigned to the word (in the range of 0 to 65535).

    Example: Declaring an Unsigned Word

    section .data
        wordValue DW 30000   ; Declare a 16-bit unsigned word with value 30000
        anotherWord DW 65535 ; Declare a 16-bit unsigned word with the maximum value (65535)
    

    In this example:

    • wordValue holds 30000, which is within the valid range for an unsigned 16-bit number.
    • anotherWord holds 65535, the maximum value that can be stored in an unsigned 16-bit word.

    2. SWORD (Signed Word)

    The SWORD data type represents a 16-bit signed integer, meaning it can store both positive and negative values. In a signed word, one bit (the most significant bit, or MSB) is used to represent the sign of the number (positive or negative). The remaining 15 bits represent the magnitude of the number.

    Range of SWORD:

    • -32768 to 32767 (in decimal)
    • 8000 to 7FFF (in hexadecimal)

    In a signed 16-bit word, the most significant bit (MSB) is the sign bit:

    • 0 means positive values (or zero).
    • 1 means negative values.

    This is known as two's complement representation, where negative numbers are encoded by subtracting the positive number from 65536 (in 16-bit form) and flipping the bits.

    Syntax:

    name DW value
    
    • DW (Define Word) is also used to define a signed 16-bit word variable. The value provided is interpreted as signed.
    • name: The label or variable name.
    • value: The signed value assigned to the word (in the range of -32768 to 32767).

    Example: Declaring a Signed Word

    section .data
        signedWord DW -30000   ; Declare a signed 16-bit word with value -30000
        anotherSigned DW 32767 ; Declare a signed 16-bit word with value 32767 (maximum positive)
    

    In this example:

    • signedWord holds -30000, which is a negative number within the valid range for a signed 16-bit number.
    • anotherSigned holds 32767, which is the maximum positive value for a signed 16-bit number.

    WORD vs. SWORD: Key Differences

    The primary difference between WORD and SWORD lies in how they treat the values they store:

    Feature WORD (Unsigned Word) SWORD (Signed Word)
    Size 16 bits (2 bytes) 16 bits (2 bytes)
    Range 0 to 65535 (decimal) -32768 to 32767 (decimal)
    Sign Only non-negative values (0 to 65535) Can represent both positive and negative values
    Use Case When you know values will be non-negative (e.g., memory addresses, image pixel values) When you need to represent signed integers (e.g., temperatures, adjustments)
    Hexadecimal Range 0000 to FFFF 8000 to 7FFF (negative), 0000 to 7FFF (positive)

    When to Use WORD vs. SWORD

    • Use WORD (unsigned) when you know that the data will always be non-negative. This could be data like:

      • Memory addresses (which cannot be negative).
      • Counts or sizes that cannot be negative (e.g., the number of items, array lengths).
      • Colors or pixel values, where values range from 0 to 255 or 0 to 65535.
    • Use SWORD (signed) when you need to store both positive and negative values, like:

      • Signed integers, where negative values make sense (e.g., temperature readings, signed measurements).
      • Arithmetic results that might be positive or negative, such as differences or adjustments.

    Examples of Using WORD and SWORD

    Example 1: Using WORD for Unsigned Data

    Let’s say we are working with a counter that tracks the number of items in a warehouse. The count can never be negative, so we will use WORD (unsigned) to store the value.

    section .data
        itemCount WORD 1000  ; Declare an unsigned word with value 1000 (number of items)
    
    • itemCount holds 1000, representing the number of items in the warehouse.

    Example 2: Using SWORD for Signed Data

    Now, let’s say we need to store the temperature of a room, which can be both positive and negative. We will use SWORD (signed) to store the value.

    section .data
        roomTemperature SWORD -15  ; Declare a signed word with the value -15 (temperature in Celsius)
    
    • roomTemperature holds -15, indicating that the room temperature is negative.

    Example 3: Handling Signed and Unsigned Data Together

    Sometimes, you might need to mix both signed and unsigned data. For instance, we might define both wordCount (which is unsigned) and temperature (which is signed):

    section .data
        wordCount WORD 5000    ; Unsigned word to hold the number of words
        temperature SWORD -5   ; Signed word to hold the temperature in Celsius
    
    • wordCount holds 5000, representing the count of words (non-negative).
    • temperature holds -5, representing the room temperature (signed).

    Conclusion

    • WORD is an unsigned 16-bit integer type, useful when the data is always non-negative and ranges from 0 to 65535.
    • SWORD is a signed 16-bit integer type, useful when the data can represent both positive and negative values, with a range of -32768 to 32767.

    Understanding the difference between these two types is critical in assembly language programming, as it helps you choose the correct type depending on whether you need to handle signed or unsigned values.

    ← Previous topic 48
    BYTE and SBYTE Data
    Next topic 50 →
    Defining DWORD and SDWORD 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
    974words
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language