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 PortalCOMP3137Real Number Constants
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 32 of 73
    Topic Study Note Illustration
    32

    Real Number Constants

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

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