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›WORD and SWORD Data
    Computer Organization and Assembly LanguageTopic 49 of 73

    WORD and SWORD Data

    6 minread
    974words
    Intermediatelevel

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

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