fsub
Floating Subtract - FC 00 00 28
fsub
Instruction Syntax
Mnemonic | Format | Flags |
fsub | frD,frA,frB | Rc = 0 |
fsub. | 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
1
0
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 (minuend) |
frB | 16-20 | Source floating-point register B (subtrahend) |
Reserved | 21-25 | 00000 |
XO | 26-30 | 10100 (20) |
Rc | 31 | Record Condition Register |
Operation
frD ← (frA) - (frB)
The contents of floating-point register frB are subtracted from the contents of floating-point register frA. The result is placed into floating-point register frD.
Note: Both operands and the result are in double-precision format. The subtraction follows IEEE-754 standard for floating-point arithmetic.
Affected Registers
Condition Register (CR1 field)
(if Rc = 1)
- Reflects floating-point exception summary and status
Floating-Point Status and Control Register (FPSCR)
Affected fields:
- FPRF (Floating-Point Result Flags)
- FX (Floating-Point Exception Summary)
- OX (Overflow Exception)
- UX (Underflow Exception)
- XX (Inexact Exception)
- VXISI (Invalid Operation Exception for ∞ - ∞)
- FR (Fraction Rounded)
- FI (Fraction Inexact)
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 Subtraction
lfd f1, minuend(r0) # Load minuend (value to subtract from) lfd f2, subtrahend(r0) # Load subtrahend (value to subtract) fsub f3, f1, f2 # f3 = f1 - f2 stfd f3, result(r0) # Store result
Subtraction with Condition Recording
lfd f1, value_a(r0) # Load first value lfd f2, value_b(r0) # Load second value fsub. f3, f1, f2 # f3 = f1 - f2, set CR1 with FP status # CR1 now reflects floating-point exception status
Calculate Difference for Comparison
# Calculate absolute difference between two values lfd f1, measurement_a(r0) # Load first measurement lfd f2, measurement_b(r0) # Load second measurement fsub f3, f1, f2 # difference = a - b fabs f4, f3 # |difference| = |a - b| stfd f4, abs_difference(r0) # Store absolute difference
Vector Subtraction
# Subtract corresponding components of two 3D vectors lfd f1, vector1_x(r0) # Load vector1.x lfd f2, vector1_y(r0) # Load vector1.y lfd f3, vector1_z(r0) # Load vector1.z lfd f4, vector2_x(r0) # Load vector2.x lfd f5, vector2_y(r0) # Load vector2.y lfd f6, vector2_z(r0) # Load vector2.z fsub f7, f1, f4 # result.x = vector1.x - vector2.x fsub f8, f2, f5 # result.y = vector1.y - vector2.y fsub f9, f3, f6 # result.z = vector1.z - vector2.z
Calculate Change/Delta
# Calculate change in value over time lfd f1, current_value(r0) # Load current value lfd f2, previous_value(r0) # Load previous value fsub f3, f1, f2 # change = current - previous stfd f3, delta(r0) # Store change
Offset Calculation
# Calculate offset from reference point lfd f1, target_position(r0) # Load target position lfd f2, reference_point(r0) # Load reference point fsub f3, f1, f2 # offset = target - reference stfd f3, offset(r0) # Store offset
Error Calculation
# Calculate error between expected and actual values lfd f1, actual_value(r0) # Load actual measured value lfd f2, expected_value(r0) # Load expected value fsub f3, f1, f2 # error = actual - expected stfd f3, error(r0) # Store error fabs f4, f3 # absolute error = |error| stfd f4, abs_error(r0) # Store absolute error
Financial Calculations
# Calculate profit/loss lfd f1, revenue(r0) # Load revenue lfd f2, costs(r0) # Load costs fsub f3, f1, f2 # profit = revenue - costs stfd f3, profit(r0) # Store profit (negative = loss)
Physics/Engineering Calculations
# Calculate displacement: final_position - initial_position lfd f1, final_position(r0) # Load final position lfd f2, initial_position(r0) # Load initial position fsub f3, f1, f2 # displacement = final - initial stfd f3, displacement(r0) # Store displacement
Temperature Difference
# Calculate temperature difference lfd f1, temp_celsius(r0) # Load temperature in Celsius lfd f2, freezing_point(r0) # Load freezing point (0°C) fsub f3, f1, f2 # degrees above freezing = temp - 0 stfd f3, above_freezing(r0) # Store result
Range Calculation
# Calculate range (max - min) lfd f1, maximum_value(r0) # Load maximum value lfd f2, minimum_value(r0) # Load minimum value fsub f3, f1, f2 # range = max - min stfd f3, range(r0) # Store range
Complex Number Subtraction
# Subtract two complex numbers: (a + bi) - (c + di) lfd f1, complex1_real(r0) # Load real part of first complex lfd f2, complex1_imag(r0) # Load imaginary part of first complex lfd f3, complex2_real(r0) # Load real part of second complex lfd f4, complex2_imag(r0) # Load imaginary part of second complex fsub f5, f1, f3 # Real part: a - c fsub f6, f2, f4 # Imaginary part: b - d # Result: f5 + f6*i