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›Real Number Constants
    Computer Organization and Assembly LanguageTopic 32 of 73

    Real Number Constants

    6 minread
    1,060words
    Intermediatelevel

    Real Number Constants in Assembly Language

    In assembly language, real number constants represent values with fractional parts (i.e., numbers that are not integers). These constants are often used in operations that require floating-point arithmetic, such as scientific calculations, graphics rendering, and digital signal processing.

    While assembly languages like MASM (Microsoft Macro Assembler) primarily focus on integer operations, they also provide support for floating-point operations using special hardware or software routines. Real numbers are typically represented using floating-point formats (like IEEE 754) and are handled differently from integer constants.

    Types of Real Number Constants

    Real number constants in assembly language are typically represented in scientific notation or fixed-point format, depending on the architecture and the assembler being used.

    1. Scientific Notation

    • Real numbers are usually written in scientific notation, where a number is represented as a base number (or significand) and an exponent. The exponent indicates how much the base should be multiplied or divided by powers of 10.
    • For example, 3.14 can be written as 3.14E0, or 3.14e0, where the E0 indicates that the exponent is zero, meaning the number is unchanged.

    Example:

    ; Declare a real number constant using scientific notation
    MOVSS xmm0, [float_3_14]   ; Load real number constant (3.14) into xmm0 register
    

    In this example:

    • 3.14 is a real number constant.
    • The MOVSS instruction is used to move the single-precision floating-point value from memory to the xmm0 register, which is part of the SSE (Streaming SIMD Extensions) set of instructions used for handling floating-point operations in modern CPUs.

    2. Fixed-Point Representation

    • In fixed-point arithmetic, real numbers are represented as integers, but the values are scaled by a fixed factor (like multiplying by 100 or 1000). For example, a real number 3.14 might be represented as the integer 314 by multiplying it by 100. The interpretation of the value depends on the program logic, which understands that the value is scaled by a factor of 100.

    • This is less common in modern systems because floating-point hardware (like SSE/AVX) is more efficient for real number operations, but it might still be used in embedded systems or in applications where floating-point arithmetic is not supported.

    Example:

    ; Real number 3.14 represented as fixed-point (314, scale by 100)
    MOV AX, 314        ; AX = 314
    

    Here, the number 314 would represent 3.14 if treated as a fixed-point number scaled by 100.


    Floating-Point Constants in Assembly Language

    Real numbers in assembly language are often handled through floating-point registers and specific instructions that work with floating-point numbers. Floating-point constants are stored in floating-point registers or memory locations that are designated for this type of data.

    The x87 FPU (Floating-Point Unit) and SSE (Streaming SIMD Extensions) are the most common ways to work with real numbers in modern processors. The x87 FPU is a stack-based floating-point unit, while SSE uses vector registers (xmm) and supports more efficient handling of floating-point operations.


    Floating-Point Operations and Instructions

    1. x87 FPU Instructions:

      • The x87 FPU provides a set of instructions for handling floating-point numbers. Floating-point constants can be loaded into the FPU stack and manipulated using these instructions.

      Example:

      FLD     st(0), 3.14    ; Load the real number constant 3.14 onto the FPU stack
      FADD    st(0), st(1)   ; Add st(1) to st(0), and store the result in st(0)
      
      • FLD loads a floating-point value into the FPU stack.
      • FADD performs an addition operation between the top two values on the stack.
    2. SSE Instructions:

      • SSE is a more modern way of handling floating-point values in x86 processors, using SIMD (Single Instruction, Multiple Data) instructions. SSE supports both single-precision (32-bit) and double-precision (64-bit) floating-point values.

      Example (Single-Precision):

      ; Declare a real number constant (single precision 3.14)
      movss xmm0, [float_3_14]  ; Load 3.14 into xmm0 (single-precision)
      

      Example (Double-Precision):

      ; Declare a real number constant (double precision 3.14159)
      movsd xmm0, [float_3_14159]  ; Load 3.14159 into xmm0 (double-precision)
      

      In these examples:

      • movss and movsd are used to move single- and double-precision floating-point numbers into the xmm0 register.
      • xmm0 is a register designed to hold floating-point data in SSE.

    Declaring Real Number Constants

    In assembly, you can declare real number constants in the data segment. The format will depend on the assembler you are using, but generally, real number constants are declared using specific directives for floating-point numbers.

    MASM Example:

    MASM uses the .data directive to declare data, and real numbers are often represented in memory using IEEE 754 single or double precision formats.

    Single Precision Example:

    .data
        float_3_14  REAL4  3.14    ; Declare a single-precision real constant 3.14
    

    In this example:

    • REAL4 is used to specify a single-precision (32-bit) floating-point number.

    Double Precision Example:

    .data
        float_3_14159 REAL8  3.14159  ; Declare a double-precision real constant 3.14159
    

    In this example:

    • REAL8 specifies a double-precision (64-bit) floating-point number.

    Floating-Point Representation (IEEE 754 Standard)

    Real numbers in assembly are typically represented according to the IEEE 754 standard, which defines how floating-point numbers are stored in memory. This standard specifies:

    1. Single Precision (32 bits): 1 sign bit, 8 exponent bits, and 23 fraction bits.
    2. Double Precision (64 bits): 1 sign bit, 11 exponent bits, and 52 fraction bits.

    The exponent is stored in biased notation, meaning a constant value is added to the exponent before storage.

    For example, the value 3.14 is stored in IEEE 754 single precision as:

    Sign bit (1 bit) | Exponent (8 bits) | Fraction (23 bits)
    

    Real Number Constants in Other Assemblers

    Other assemblers may have different conventions or formats for defining real number constants.

    • GAS (GNU Assembler): In GAS (part of the GNU toolchain), you might see floating-point constants expressed in a similar way using .float or .double directives.
      .data
          .float 3.14        ; Single precision
          .double 3.14159    ; Double precision
      

    Conclusion

    Real number constants in assembly language are used for operations that involve floating-point arithmetic, such as scientific computations, graphics, and signal processing. These constants are represented in either scientific notation or fixed-point format, and operations on them are performed using floating-point instructions provided by the hardware (such as the x87 FPU or SSE/AVX instructions for modern CPUs). Understanding how to declare, represent, and manipulate real number constants is crucial for efficiently working with real numbers in low-level programming.

    By using appropriate assembly instructions and understanding the formats like IEEE 754, programmers can perform precise and efficient floating-point calculations in assembly.

    Previous topic 31
    Integer Expressions
    Next topic 33
    Character Constants

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