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 PortalDC-221Machine Level Represen…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    DC-221

    Computer Organization and Assembly Language

    Progress0 / 35 done
    Topics35
    1Introduction to Computer Systems2Information is Bits + Context3Programs are Translated by Other Programs4Understanding Compilation Systems5Processors Read and Interpret Instructions6Caches Matter7Storage Devices Form a Hierarchy8The Operating System Manages the Hardware9Systems Communicate Using Networks10Representing and Manipulating Information11Information Storage12Integer Representations13Integer Arithmetic14Floating Point15Machine-Level Representation of Programs16A Historical Perspective17Program Encodings18Data Formats19Accessing Information20Arithmetic and Logical Operations21Control22Procedures23Array Allocation and Access24Heterogeneous Data Structures25Understanding Pointers26Using the GDB Debugger27Out-of-Bounds Memory References and Buffer Overflow
    28Extending IA-32 to 64 Bits29Machine-Level Representations of Floating-Point Programs30Processor Architecture31The Y86 Instruction Set Architecture32Logic Design and the Hardware Control Language (HCL)33Sequential Y86 Implementations34General Principles of Pipelining35Pipelined Y86 Implementations
    3 min read
    Topic 29 of 35
    Topic Study Note Illustration
    29

    Machine-Level Representations of Floating-Point Programs

    Floating-point representation is a way of encoding real numbers in a computer using binary. Floating-point programs use this representation to handle calculations involving non-integer values, such as...

    Machine-Level Representations of Floating-Point Programs

    Floating-point representation is a way of encoding real numbers in a computer using binary. Floating-point programs use this representation to handle calculations involving non-integer values, such as decimals and fractions. At the machine level, floating-point operations are managed by a component called the Floating-Point Unit (FPU).


    1. Floating-Point Number Representation

    A floating-point number is generally represented using three components:

    1. Sign (S): Determines if the number is positive (0) or negative (1).
    2. Exponent (E): Represents the scaling factor by raising 2 to a power.
    3. Mantissa (M) (or Fraction): Represents the significant digits of the number.

    The general formula is:

    Value=(−1)S×M×2(E−Bias)\text{Value} = (-1)^{S} \times M \times 2^{(E - \text{Bias})}Value=(−1)S×M×2(E−Bias)

    IEEE 754 Standard

    The IEEE 754 standard defines how floating-point numbers are represented and processed. Two common formats are:

    • Single Precision (32-bit):
      • 1 bit for the sign
      • 8 bits for the exponent
      • 23 bits for the mantissa
    • Double Precision (64-bit):
      • 1 bit for the sign
      • 11 bits for the exponent
      • 52 bits for the mantissa

    2. Floating-Point Operations

    Floating-point programs involve various operations such as addition, subtraction, multiplication, division, and square roots. At the machine level:

    • Floating-point operations are implemented using dedicated FPU instructions.
    • These instructions follow specific rules to handle rounding, overflow, underflow, and precision.

    Example Instructions (x86 Assembly):

    • Addition: addss (single precision), addsd (double precision)
    • Multiplication: mulss, mulsd
    • Division: divss, divsd
    • Square Root: sqrtss, sqrtsd

    3. Floating-Point Arithmetic Challenges

    1. Precision Errors:

      • Floating-point numbers have limited precision because only a finite number of bits are available for the mantissa.
      • Example: The result of 0.1+0.20.1 + 0.20.1+0.2 might not exactly equal 0.30.30.3 due to binary rounding.
    2. Rounding Modes:

      • IEEE 754 supports rounding modes like round-to-nearest, round-toward-zero, round-up, and round-down.
    3. Overflow and Underflow:

      • Overflow: When a number is too large to represent.
      • Underflow: When a number is too small (close to zero) to represent.
    4. Special Values:

      • NaN (Not a Number): Result of undefined operations like 00\frac{0}{0}00​.
      • Infinity: Represented by maximum exponent and zero mantissa.

    4. Floating-Point Representation in Programs

    When writing programs in high-level languages, the compiler translates floating-point calculations into machine-level instructions. For example:

    float x = 1.5, y = 2.5, z;
    z = x + y;
    

    The compiler generates machine code that performs the addition using FPU instructions.

    Assembly Representation:

    movss xmm0, DWORD PTR [x]    ; Load x into register
    movss xmm1, DWORD PTR [y]    ; Load y into register
    addss xmm0, xmm1             ; Add x and y, store result in xmm0
    movss DWORD PTR [z], xmm0    ; Store result into z
    

    5. Performance and Optimization

    • Hardware Support: Modern CPUs have highly optimized FPUs for efficient floating-point operations.
    • Vectorization: SIMD (Single Instruction, Multiple Data) instructions like AVX enable parallel floating-point operations.
    • Compiler Optimizations: Compilers rearrange and optimize floating-point instructions to improve performance, but this can sometimes alter precision.

    6. Summary Table: Machine-Level Floating-Point Programs

    Concept Details
    Floating-Point Components Sign, Exponent, Mantissa (IEEE 754 standard).
    Precision Formats Single Precision (32-bit), Double Precision (64-bit).
    FPU Instructions addss, addsd, mulss, mulsd, sqrtss, sqrtsd.
    Challenges Precision errors, rounding modes, overflow, underflow, special values (NaN, Infinity).
    High-Level to Machine Compilers translate floating-point operations into FPU instructions.
    Optimization SIMD, AVX instructions, and compiler techniques for better performance.
    ← Previous topic 28
    x86-64: Extending IA-32 to 64 Bits
    Next topic 30 →
    Processor Architecture

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    3mremaining
    590words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language