7.ece5436

63
ECE 5436/6336 Advanced Microprocessor Systems Pauline Markenscoff N320 Engineering Building 1 E-mail: [email protected] Week 9

Upload: karthik-vadlapatla

Post on 01-May-2017

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 7.ECE5436

ECE 5436/6336���Advanced Microprocessor

Systems

Pauline Markenscoff N320 Engineering Building 1 E-mail: [email protected] Week 9

Page 2: 7.ECE5436

2

Page 3: 7.ECE5436

Floating Point Representations

Page 4: 7.ECE5436

Common Format Components

  Each codes a normalized number whose “binary scientific notation” would be ���±1.dd…d x 2exp

  Sign bit •  0 for positive and 1 for negative

  Exponent field •  Actual exponent exp plus a bias •  Bias gives an alternative to 2’s complement

  Fraction (“mantissa”) field

Page 5: 7.ECE5436

IEEE Single Precision Format

  32-bit format •  Sign bit •  8-bit biased exponent (the actual exponent in the

normalized binary “scientific” format plus 127) •  23-bit fraction (the fraction in the scientific format without

the leading 1 bit)

  Generated by REAL4 directive

Page 6: 7.ECE5436

IEEE Double Precision Format

  64-bit format •  Sign bit •  11-bit biased exponent (the actual exponent in the

normalized binary scientific format plus 1023) •  52-bit fraction (the fraction in the scientific format without

the leading 1 bit)   Generated by REAL8 directive

Page 7: 7.ECE5436

Extended Precision Format

  80-bit format •  Sign bit •  15-bit biased exponent (the actual exponent in a normalized

binary scientific format plus 16,383) •  64-bit fraction (the fraction in the scientific format

including the leading 1 bit)   Generated by REAL10 directive

Page 8: 7.ECE5436

Floating Point Formats

format total bits exponent bits

fraction bits

approximate maximum

approximate minimum

approximate decimal

precision

single 32 8 23 3.40×1038 1.18×10-38 7 digits

double 64 11 52 1.79×10308 2.23×10-308 15 digits

extended double 80 15 64 1.19×104932 3.37×10-4932 19 digits

• These are for normalized numbers •  Binary scientific notation mantissa written starting with 1 and binary

point •  Zero cannot be normalized

•  +0 represented by a pattern of all 0 bits • Also formats for ± ∞ and NaN ("not a number”)

Page 9: 7.ECE5436

Assembler Data Declarations

number1 REAL4 78.375 number2 REAL8 -78.375 number3 REAL10 78.375 assembly listing 00000000 429CC000 number1 REAL4 78.375 00000004 number2 REAL8 -78.375

C053980000000000 0000000C number3 REAL10 78.375

40059CC0000000000000

Page 10: 7.ECE5436

80x86 Floating Point Architecture

Page 11: 7.ECE5436

Floating Point Unit

FPU is independent of integer unit Eight 80-bit registers, organized as a stack

•  ST, the stack top, also called ST(0) •  ST(1), the register just below the stack top •  ST(2), the register just below ST(1) •  ST(3), ST(4), ST(5), ST(6) •  ST(7), the register at the bottom of the stack

Several 16-bit control registers, including status word

Page 12: 7.ECE5436

Load Instructions

fld realMemoryOperand •  Loads stack top ST with floating point data value •  Values already on the stack are pushed down

fld integerMemoryOperand •  Converts integer value to corresponding fp value that is

pushed onto the stack fld st(nbr)

•  Pushes a copy of st(nbr) onto the fp stack

Page 13: 7.ECE5436

More Loads and finit

fld1 •  Pushes 1.0 onto floating point stack

fld0 •  Pushes 0.0 onto fp stack

fldpi •  Pushes π onto fp stack …and others

finit initializes the floating point processor, clearing the stack

Page 14: 7.ECE5436

Store Instructions

fst realMemoryOperand •  Copies stack top ST value to memory

fstp realMemoryOperand •  Copies stack top ST value to memory and pops the floating

point stack fist integerMemoryOperand

•  Copies stack top ST value to memory, converting to integer fistp integerMemoryOperand

•  Same as fist, but also pops the floating point stack

Page 15: 7.ECE5436

Exchange Instructions

fxch •  Exchange values in ST and ST(1)

fxch st(nbr) •  Exchange ST and ST(nbr)

Page 16: 7.ECE5436

Addition Instructions

fadd •  adds ST(1) and ST; pushes sum on stack

fadd st, st(nbr) •  adds ST(nbr) and ST; sum replaces ST

fadd st(nbr), st •  adds ST(nbr) and ST; sum replaces ST(nbr)

faddp st(nbr), st •  adds ST(nbr) and ST; sum replaces ST(nbr); old ST

popped from stack

Page 17: 7.ECE5436

More Addition Instructions

fadd realMemoryOperand •  Adds ST and real memory operand; ���

sum replaces ST fiadd integerMemoryOperand

•  Adds ST and integer memory operand; ���sum replaces ST

Page 18: 7.ECE5436

Addition Example

Before Instructions After

10.0 ST fadd st,st(3) 56.0 ST

20.0 ST(1) fadd fpValue 20.0 ST(1)

30.0 ST(2) fiadd intValue 30.0 ST(2)

40.0 ST(3) 40.0 ST(3)

ST(4) ST(4)

ST(5) ST(5)

ST(6) ST(6)

ST(7) ST(7)

Data declarations fpValue REAL4 5.0

intValue DWORD 1

Page 19: 7.ECE5436

Subtraction Instructions

fsub •  pops ST and ST(1); calculates ST(1) - ST; pushes difference onto the stack

fsub st(nbr), st •  calculates ST(nbr) - ST; ���

replaces ST(nbr) by the difference fsub st, st(nbr)

•  calculates ST - ST(nbr); ���replaces ST by the difference

Page 20: 7.ECE5436

More Subtraction Instructions

fsub realMemoryOperand •  calculates ST - real number from memory; replaces ST by the difference

fisub integerMemoryOperand •  calculates ST - integer from memory; ���

replaces ST by the difference fsubp st(nbr), st

•  calculates ST(nbr) - ST; ���replaces ST(nbr) by the difference; ���pops ST from the stack

Page 21: 7.ECE5436

Reversed Subtraction Instructions

fsubr •  pops ST and ST(1); calculates ST - ST(1) ; pushes difference onto the stack

fsubr st(nbr), st •  calculates ST - ST(nbr); ���

replaces ST(nbr) by the difference fsubr st, st(nbr)

•  calculates ST(nbr) - ST; ���replaces ST by the difference

Page 22: 7.ECE5436

More Reversed Subtraction Instructions

fsubr realMemoryOperand •  calculates real number from memory - ST; replaces ST by the difference

fisubr integerMemoryOperand •  calculates integer from memory - ST; ���

replaces ST by the difference fsubpr st(nbr), st

•  calculates ST - ST(nbr); ���replaces ST(nbr) by the difference; ���pops ST from the stack

Page 23: 7.ECE5436

Multiplication Instructions

fmul •  pops ST and ST(1); ���

multiplies these values; ���pushes product onto the stack

fmul st(nbr), st •  multiplies ST(nbr) and ST; ���

replaces ST(nbr) by the product fmul st, st(num)

•  multiplies ST and ST(nbr); ���replaces ST by the product

Page 24: 7.ECE5436

More Multiplication Instructions

fmul realMemoryOperand •  multiplies ST and real number from memory; replaces ST by the product

fimul integerMemoryOperand •  multiplies ST and integer from memory; replaces ST by the product

fmulp st(nbr), st •  multiplies ST(nbr) and ST; ���

replaces ST(nbr) by the product; ���pops ST from stack

Page 25: 7.ECE5436

Division Instructions

fdiv •  pops ST and ST(1); ���

calculates ST(1) / ST; ���pushes quotient onto the stack

fdiv st(nbr), st •  calculates ST(nbr) / ST; ���

replaces ST(nbr) by the quotient fdiv st,st(nbr)

•  calculates ST / ST(nbr); ���replaces ST by the quotient

Page 26: 7.ECE5436

More Division Instructions

fdiv realMemoryOperand •  calculates ST / real number from memory; replaces ST by the quotient

fidiv integerMemoryOperand •  calculates ST / integer from memory; ���

replaces ST by the quotient fdivp st(nbr),st

•  calculates ST(nbr) / ST; ���replaces ST(nbr) by the quotient; ���pops ST from the stack

Page 27: 7.ECE5436

Reversed Division Instructions

Similar to reversed multiplication--each division instruction has a version that reverses operands used as dividend and divisor •  fdivr (pops ST and ST(1),calculates ST/ST(1);pushes quotient onto the stack)

•  fidivr memory (integer) (calculates integer from memory/ST; replaces ST by the quotient)

•  fdivpr st(num),st calculates ST/ST(num); replaces ST(num) by the quotient; pops ST from the stack.

Page 28: 7.ECE5436

Miscellaneous Instructions

fabs •  Absolute value: ST := | ST |

fchs •  Change sign: ST := - ST

frndint •  Rounds ST to an integer value

fsqrt •  Replace ST by its square root There are also trigonometric, exponential and logarithmic functions

Page 29: 7.ECE5436

Comparisons Each instruction compares ST with some other operand Sets “condition code” bits 14, 10 and 8 in the status word register

•  These bits are named C3, C2 and C0

result of comparison C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

Page 30: 7.ECE5436

Comparison Instructions

fcom •  compares ST and ST(1)

fcom st(nbr) •  compares ST and ST(nbr)

fcom realMemoryOperand •  compares ST and real number in memory

ficom integerMemoryOperand •  compares ST and integer in memory

Page 31: 7.ECE5436

More Comparison Instructions ftst

•  compares ST and 0.0 fcomp

•  compares ST and ST(1); then pops stack fcompp

•  compares ST and ST(1); then pops stack twice

result of comparison

C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

Page 32: 7.ECE5436

Yet More Comparison Instructions

fcomp st(nbr) •  compares ST and ST(nbr); then pops stack

fcomp realMemoryOperand •  compares ST and real number in memory; then pops stack

ficomp integerMemoryOperand •  compares ST and integer in memory; then pops stack

Page 33: 7.ECE5436

Status Word Access Conditional jump instructions look at bits in flags register, not in status word. The fstsw instructions provide access to the status word bits.

fstsw memoryWord •  copies status register to memory word

fstsw AX •  copies status register to AX

sahf;shifts condition code bits to

flags •  sahf instruction puts C3 in the ZF position, C2 in the PF position, and C0 in the CF position

Page 34: 7.ECE5436

Programming With Floating Point Instructions

Page 35: 7.ECE5436

FP Program-Example 1 ; compute roots of quadratic equation .586

.MODEL FLAT

.STACK 4096

.DATA

aa REAL4 2.0

bb REAL4 -1.0

cc REAL4 -15.0

discr REAL4 ? x1 REAL4 ?

x2 REAL4 ?

four DWORD 4

two DWORD 2

ax2 + bx + c = 0

x1 =!b+ b2 ! 4ac

2a

x2 =!b! b2 ! 4ac

2a

Page 36: 7.ECE5436

FP Program- Example 1 .CODE main PROC

finit ; initialize FPU

fld bb ; b in ST

fmul bb ; b*b

fild four ; 4.0 in ST

fmul aa ; 4*a

fmul cc ; 4*a*c

fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

Page 37: 7.ECE5436

FP Program-Example 1 fsqrt ; sqrt(b*b-4*a*c) in ST fst st(1) ; copy to ST(1)

fsub bb ; -b + sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 37

Page 38: 7.ECE5436

FP Program-Example 1 ; compute roots of quadratic equation .586

.MODEL FLAT

.STACK 4096

.DATA

aa REAL4 2.0

bb REAL4 -1.0

cc REAL4 -15.0

discr REAL4 ? x1 REAL4 ?

x2 REAL4 ?

four DWORD 4

two DWORD 2

ax2 + bx + c = 0

x1 =!b+ b2 ! 4ac

2a

x2 =!b! b2 ! 4ac

2a

Page 39: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b

fild four ; 4.0 in ST

fmul aa ; 4*a

fmul cc ; 4*a*c

fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 40: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST

fmul aa ; 4*a

fmul cc ; 4*a*c

fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 41: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a

fmul cc ; 4*a*c

fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

4.0 ST0

b*b ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 42: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c

fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

4*a ST0

b*b ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 43: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

4*a*c ST0

b*b ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 44: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c fsub ; b*b-4*a*c fldz ; 0.0 in ST

fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 45: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c fsub ; b*b-4*a*c fldz ; 0.0 in ST fxch ; b*b-4*a*c in ST; 0.0 in ST(1)

fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

0 ST0

b*b-4*a*c ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 46: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c fsub ; b*b-4*a*c fldz ; 0.0 in ST fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ?

fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 47: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; initialize FPU fld bb ; b in ST fmul bb ; b*b fild four ; 4.0 in ST fmul aa ; 4*a fmul cc ; 4*a*c fsub ; b*b-4*a*c fldz ; 0.0 in ST fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ? fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 48: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; fld bb ; fmul bb ; fild four ; fmul aa ; fmul cc ; fsub ; fldz ; fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ? fstsw ax ; copy condition code bits to AX

sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

result of comparison

C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

Page 49: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; fld bb ; fmul bb ; fild four ; fmul aa ; fmul cc ; fsub ; fldz ; fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ? fstsw ax ; copy condition code bits to AX sahf ; shift condition code bits to flags

jnae endGE ; skip if not

fsqrt ; sqrt(b*b-4*a*c) in ST

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

result of comparison

C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

Page 50: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; fld bb ; fmul bb ; fild four ; fmul aa ; fmul cc ; fsub ; fldz ; fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ? fstsw ax ; copy condition code bits to AX sahf ; shift condition code bits to flags jnae endGE ; skip if not

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

result of comparison

C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

sahf instruction puts C3 in the ZF position, C2 in the PF position, and C0 in the CF position.

Page 51: 7.ECE5436

FP Program-Example 1 .CODE main PROC

finit ; fld bb ; fmul bb ; fild four ; fmul aa ; fmul cc ; fsub ; fldz ; fxch ; b*b-4*a*c in ST; 0.0 in ST(1) fcom st(1) ; b*b-4*a*c >= 0 ? fstsw ax ; copy condition code bits to AX sahf ; shift condition code bits to flags jnae endGE ; skip if not

b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

result of comparison

C3 (14)

C2 (10)

C0 (8)

ST > operand 0 0 0 ST < operand 0 0 1 ST = operand 1 0 0 not comparable 1 1 1

sahf instruction puts C3 in the ZF position, C2 in the PF position, and C0 in the CF position.

Page 52: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1)

fsub bb ; -b + sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 52

√b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 53: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 53

√b*b-4*a*c ST0

√b*b-4*a*c ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 54: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 54

-b+√b*b-4*a*c ST0

√b*b-4*a*c ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 55: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 55

(-b+√b*b-4*a*c)/a ST0

√b*b-4*a*c ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 56: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack

fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 56

(-b+√b*b-4*a*c)/2*a ST0

√b*b-4*a*c ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

Page 57: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c)

fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 57

√b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 58: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c)

fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 58

-√b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 59: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a

fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 59

-b-√b*b-4*a*c ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 60: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 60

(-b-√b*b-4*a*c)/a ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 61: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a)

fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 61

(-b-√b*b-4*a*c)/a ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 62: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x2 ; save and pop stack

endGE:

mov eax, 0 ; exit

ret

main ENDP

END 62

(-b-√b*b-4*a*c)/2*a ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a

Page 63: 7.ECE5436

FP Program-Example 1

fsqrt ; sqrt(b*b-4*a*c) in ST

fst st(1) ; copy to ST(1) fsub bb ; -b + sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x1 ; save and pop stack fchs ; -sqrt(b*b-4*a*c) fsub bb ; -b -sqrt(b*b-4*a*c) fdiv aa ; (-b + sqrt(b*b-4*a*c))/a fidiv two ; (-b + sqrt(b*b-4*a*c))/(2*a) fstp x2 ; save and pop stack endGE:

mov eax, 0 ; exit

ret

main ENDP

END 63

0

ST0

0 ST1 0 ST2 0 ST3 0 ST4 0 ST5 0 ST6 0 ST7

X1=(-b+√b*b-4*a*c)/2*a X2=(-b-√b*b-4*a*c)/2*a