20
Floating-Point Operations Chapter 18 S. Dandamudi

Al2ed chapter18

Embed Size (px)

Citation preview

Page 1: Al2ed chapter18

Floating-Point Operations

Chapter 18

S. Dandamudi

Page 2: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 2

Outline

• Introduction• FPU organization

Data registers Control and status registers Tag register

• Floating-point instructions Data movement Addition/Subtraction Multiplication/Division Comparison Miscellaneous

• Illustrative examples

Page 3: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 3

Introduction

• Three components Sign

» Identified the number

– positive or negative

Mantissa Exponent

• Follows IEEE 754 standard• More details in Appendix A

Page 4: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 4

FPU Organization

• FPU consists of Data registers

» 8 registers ST0, ST1, …, ST7

» Organized as a register stack

» Names are not statically assigned

Control and status registers Pointer registers

» Instruction and data pointer registers

» Provides support for programmed exception handlers

» Not discussed

Page 5: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 5

FPU Organization (cont’d)

FPU Registers

Page 6: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 6

FPU Organization (cont’d)

FPU Control Register

Page 7: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 7

FPU Organization (cont’d)

FPU Status Register

Page 8: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 8

FPU Organization (cont’d)

• FPU Tag Register Two bits for each register Gives the following information

00 valid

01 zero

10 special (invalid, infinity, or denormal)

11 empty

Page 9: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 9

Floating-Point Instructions

• Several floating-point instructions for Data movement Addition/Subtraction Multiplication/Division Comparison Miscellaneous

• These instructions, by default, affect the flags as follows: Flag bits C0, C2, and C3 are undefined C1 is updated to indicate overflow/underflow condition

Page 10: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 10

Floating-Point Instructions (cont’d)

• Data movement Two types

» Load and store

Load instructionsfld src

– Pushes src onto the FPU stack– src operand can be in a register or in memory

– It can be a single-precision (32 bits), double-precision (64 bits) or extended (80-bit) floating-point number

Single- and double-precision numbers are converted to extended format

Page 11: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 11

Floating-Point Instructions (cont’d)

• FP Instructions to push constantsInstruction Description

fldz Push +0.0 onto the stack

fld1 Push +1.0 onto the stack

fldpi Push onto the stack

fldl2t Push log210 onto the stack

fldl2e Push log2e onto the stack

fldlg2 Push log102 onto the stack

fldln2 Push loge2 onto the stack

To load an integer: fild src

Page 12: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 12

Floating-Point Instructions (cont’d)

• Store instructionsfst dest

Stores the top-of-stack value at dest» Does not pop it off the stack

To the value use

fstp dest Integer version of the store instruction

fist dest Its pop version is

fistp dest

Page 13: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 13

Floating-Point Instructions (cont’d)

• Additionfadd src

adds the number in memory at src to that in ST0 and stores the result in ST0

» Does not pop the stack

Two operand version

fadd dest,src– Both dest and src must be FPU registers

Its pop version

faddp dest,src Integer version

fiadd src

Page 14: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 14

Floating-Point Instructions (cont’d)

• Subtractionfsub src

Performs ST0 = ST0 src» Does not pop the stack

Two operand version

fsub dest,src– Both dest and src must be FPU registers

Its pop version

fsubp dest,src Reverse subtract version

fsubr src– Performs ST0 = src – ST0

Page 15: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 15

Floating-Point Instructions (cont’d)

• Multiplicationfmul src

Performs ST0 = ST0 src» Does not pop the stack

Two operand versionfmul dest,src

– Both dest and src must be FPU registers Its pop version

fmulp dest,src Special pop version with no operands

fmulp Performs ST0 = ST1 * ST0 Multiplication by integer

fimul src

Page 16: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 16

Floating-Point Instructions (cont’d)

• Divisionfdiv src

Performs ST0 = ST0 / src» Does not pop the stack

Two operand versionfdiv dest,src Performs dest = dest/src

– Both dest and src must be FPU registers Its pop version

fdivp dest,src Reverse division version

fdivr src Performs ST0 = src / ST0 Multiplication by integer

fidiv src

Page 17: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 17

Floating-Point Instructions (cont’d)

• Comparisonfcom src

Compares the value in ST0 with src and sets the FPU flags C0, C2, and C3 as follows

Relationship C3 C2 C0

ST0 > src 0 0 0

ST0 = src 1 0 0

ST0 < src 0 0 1

Not comparable 1 1 1

Double pop version

fcompp– Compares ST0 and ST1 and pops these two values from the

stack

Page 18: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 18

Floating-Point Instructions (cont’d)

• Comparison (cont’d) Comparison with an integer

ficom src Comparison with zero

ftst To examine number type

fxam– Examines the number in ST0 and returns its sign in C1

(0 for positive, 1 for negative)

– C0, C2, and C3 return the following information

Type C3 C2 C0Unsupported 0 0 0NaN 0 0 1Normal 0 1 0Infinity 0 1 1Zero 1 0 0Empty 1 0 1Denormal 1 1 0

Page 19: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 19

Floating-Point Instructions (cont’d)

• Miscellaneous Change the sign

fchs– Changes the sign of the number in ST0

Loading the control word

fldcw src Storing the control word

fstcw dest Storing the status word

fstsw dest

Page 20: Al2ed chapter18

2005

To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

S. Dandamudi Chapter 18: Page 20

Illustrative Examples

• Example 1 Array sum

• Example 2 Quadratic equation solution

• Example 3 Array sum --- Inline version

Last slide