fdiv
Floating Divide - FC 00 00 24
fdiv

Instruction Syntax

Mnemonic Format Flags
fdiv frD,frA,frB Rc = 0
fdiv. frD,frA,frB Rc = 1

Instruction Encoding

1
1
1
1
1
1
D
D
D
D
D
A
A
A
A
A
B
B
B
B
B
0
0
0
0
0
0
0
0
1
0
0
1
0
Rc

Field Bits Description
Primary Opcode 0-5 111111 (0x3F)
frD 6-10 Destination floating-point register
frA 11-15 Source floating-point register A (dividend)
frB 16-20 Source floating-point register B (divisor)
Reserved 21-25 00000
XO 26-30 10010 (18)
Rc 31 Record Condition Register

Operation

frD ← (frA) ÷ (frB)

The contents of floating-point register frA are divided by the contents of floating-point register frB. The result is placed into floating-point register frD.

Note: Both operands and the result are in double-precision format. The division follows IEEE-754 standard for floating-point arithmetic. Division by zero will set appropriate exception flags.

Affected Registers

Condition Register (CR1 field)

(if Rc = 1)

Floating-Point Status and Control Register (FPSCR)

Affected fields:

For more information on floating-point status see Section 2.1.4, "Floating-Point Status and Control Register (FPSCR)," in the PowerPC Microprocessor Family: The Programming Environments manual.

Examples

Basic Floating-Point Division

lfd f1, dividend(r0)       # Load dividend
lfd f2, divisor(r0)        # Load divisor
fdiv f3, f1, f2            # f3 = f1 ÷ f2
stfd f3, result(r0)        # Store result

Division with Exception Checking

lfd f1, numerator(r0)      # Load numerator
lfd f2, denominator(r0)    # Load denominator
fdiv. f3, f1, f2           # f3 = f1 ÷ f2, set CR1 with FP status
# Check for division by zero or other exceptions in CR1

Average Calculation

# Calculate average of values
lfd f1, sum_of_values(r0)  # Load sum
lfd f2, count_values(r0)   # Load count
fdiv f3, f1, f2            # average = sum ÷ count
stfd f3, average(r0)       # Store average

Ratio Calculation

# Calculate ratio between two quantities
lfd f1, quantity_a(r0)     # Load first quantity
lfd f2, quantity_b(r0)     # Load second quantity
fdiv f3, f1, f2            # ratio = a ÷ b
stfd f3, ratio(r0)         # Store ratio

Unit Conversion

# Convert meters to feet (1 meter = 3.28084 feet)
lfd f1, meters(r0)         # Load value in meters
lfd f2, meter_to_feet(r0)  # Load conversion factor (3.28084)
fmul f3, f1, f2            # Alternative: multiply by factor
# Or divide by reciprocal
lfd f4, feet_to_meter(r0)  # Load reciprocal (1/3.28084)
fdiv f5, f1, f4            # feet = meters ÷ (1/3.28084)

Normalization

# Normalize a vector (divide by magnitude)
lfd f1, vector_x(r0)       # Load vector.x
lfd f2, vector_y(r0)       # Load vector.y  
lfd f3, vector_z(r0)       # Load vector.z
lfd f4, magnitude(r0)      # Load precalculated magnitude
fdiv f5, f1, f4            # normalized.x = vector.x ÷ magnitude
fdiv f6, f2, f4            # normalized.y = vector.y ÷ magnitude
fdiv f7, f3, f4            # normalized.z = vector.z ÷ magnitude

Percentage Calculation

# Calculate percentage: (part ÷ whole) × 100
lfd f1, part_value(r0)     # Load part
lfd f2, whole_value(r0)    # Load whole
lfd f3, hundred(r0)        # Load 100.0
fdiv f4, f1, f2            # ratio = part ÷ whole
fmul f5, f4, f3            # percentage = ratio × 100
stfd f5, percentage(r0)    # Store percentage

Financial Calculations

# Calculate price per unit
lfd f1, total_price(r0)    # Load total price
lfd f2, quantity(r0)       # Load quantity
fdiv f3, f1, f2            # price_per_unit = total ÷ quantity
stfd f3, unit_price(r0)    # Store unit price

Safe Division with Zero Check

# Division with zero checking
lfd f1, dividend(r0)       # Load dividend
lfd f2, divisor(r0)        # Load divisor
lfd f3, zero_constant(r0)  # Load 0.0 for comparison
fcmpo cr0, f2, f3          # Compare divisor with zero
beq division_by_zero       # Branch if divisor is zero
fdiv f4, f1, f2            # Safe division
stfd f4, result(r0)        # Store result
b division_done
division_by_zero:
    # Handle division by zero case
    lfd f4, infinity(r0)    # Load infinity or error value
    stfd f4, result(r0)     # Store error result
division_done:

Related Instructions

fdivs, fmul, fmuls, fres, fcmpo

Back to Index