Interrupts & Input/output

Download Report

Transcript Interrupts & Input/output

Floating-Point Operations
Chapter 18
S. Dandamudi
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
2005
 S. Dandamudi
Chapter 18: Page 2
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Introduction
• Three components
 Sign
» Identified the number
– positive or negative
 Mantissa
 Exponent
• Follows IEEE 754 standard
• More details in Appendix A
2005
 S. Dandamudi
Chapter 18: Page 3
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
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
2005
 S. Dandamudi
Chapter 18: Page 4
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
FPU Organization (cont’d)
FPU Registers
2005
 S. Dandamudi
Chapter 18: Page 5
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
FPU Organization (cont’d)
FPU Control Register
2005
 S. Dandamudi
Chapter 18: Page 6
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
FPU Organization (cont’d)
FPU Status Register
2005
 S. Dandamudi
Chapter 18: Page 7
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
FPU Organization (cont’d)
• FPU Tag Register
 Two bits for each register
 Gives the following information
00
01
10
11
2005
valid
zero
special (invalid, infinity, or denormal)
empty
 S. Dandamudi
Chapter 18: Page 8
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
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
2005
 S. Dandamudi
Chapter 18: Page 9
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Data movement
 Two types
» Load and store
 Load instructions
fld
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
2005
 S. Dandamudi
Chapter 18: Page 10
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• FP Instructions to push constants
Instruction
Description
fldz
Push +0.0 onto the stack
fld1
Push +1.0 onto the stack
fldpi
Push p 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
2005
 S. Dandamudi
Chapter 18: Page 11
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Store instructions
fst
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
2005
 S. Dandamudi
Chapter 18: Page 12
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Addition
fadd
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
2005
 S. Dandamudi
Chapter 18: Page 13
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Subtraction
fsub
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
2005
 S. Dandamudi
Chapter 18: Page 14
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Multiplication
fmul
src
 Performs ST0 = ST0  src
» Does not pop the stack
 Two operand version
fmul
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
2005
 S. Dandamudi
Chapter 18: Page 15
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Division
fdiv
src
 Performs ST0 = ST0 / src
» Does not pop the stack
 Two operand version
fdiv
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
2005
 S. Dandamudi
Chapter 18: Page 16
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Comparison
fcom
src
 Compares the value in ST0 with src and sets the FPU flags C0,
C2, and C3 as follows
Relationship
ST0 > src
ST0 = src
ST0 < src
Not comparable
C3 C2 C0
0 0 0
1 0 0
0 0 1
1 1 1
 Double pop version
fcompp
– Compares ST0 and ST1 and pops these two values from the
stack
2005
 S. Dandamudi
Chapter 18: Page 17
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Floating-Point Instructions (cont’d)
• Comparison (cont’d)
 Comparison with an integer
ficom
src
 Comparison with zero
ftst
 To examine number type
fxam
Type
C3 C2 C0
Unsupported 0 0 0
NaN
0 0 1
Normal
0 1 0
Infinity
0 1 1
Zero
1 0 0
Empty
1 0 1
Denormal
1 1 0
– 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
2005
 S. Dandamudi
Chapter 18: Page 18
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
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
2005
 S. Dandamudi
Chapter 18: Page 19
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.
Illustrative Examples
• Example 1
 Array sum
• Example 2
 Quadratic equation solution
• Example 3
 Array sum --- Inline version
Last slide
2005
 S. Dandamudi
Chapter 18: Page 20
To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.