Fpu

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Fpu as PDF for free.

More details

  • Words: 381
  • Pages: 13
FPU PROGRAMING EXAMPLES

;Program to find the area of 5 circles whose radii are stored in array RAD. .MODEL SMALL .386 .387 .DATA RAD DD 2.34, 5.66, 9.33, 234.5, 23.4 AREA DD 5 DUP(?) .CODE .STARTUP MOV SI,0

;source element 0

MOV DI,0

;destination element 0

MOV CX,5

;count of 5

MAIN1: FLD RAD [SI]

;radius to ST

FMUL ST,ST(0)

;square radius

FLDPI

;π to ST

FMUL

;multiply ST= ST * ST(1)

FSTP AREA [DI]

;save area

INC SI INC DI LOOP MAIN1 .EXIT END

;Program to find the resonant frequency of a LC tank circuit. .MODEL SMALL .386 .387 .DATA RESO DD 1 DUP(?) L1

DD 0.000001

C1

DD 0.000001

TWO

DD 2.0 .CODE .STARTUP

;resonant frequency ;inductance ;capacitance ;constant

FLD L1

;get L

FMUL C1

;find LC

FSQRT

;find √LC

FMUL TWO

;find 2√LC

FLDPI

;get π

FMUL

;get 2π√LC

FLD1

;get 1

FDIVR

;form 1/2π√LC

FSTP RESO

;save frequency

.EXIT END

;Program to find the roots of a quadratic equation. .MODEL SMALL .386 .387 .DATA TWO

DD

2.0

FOUR DD

4.0

A1

DD

1.0

B1

DD

0.0

C1

DD

-9.0

R1

DD

?

R2

DD

?

.CODE .STARTUP

FLDZ FST R1

;clear roots

FSTP R2 FLD TWO FMUL A1

;form 2a

FLD FOUR FMUL A1 FMUL C1

;form 4ac

FLD B1 FMUL B1

;form b²

FSUBR

;form b²-4ac

FTST

;test b²-4ac for zero

FSTSW AX

;copy status register to AX

SAHF

;move to flags

JZ ROOTS1

;if b²-4ac is zero

FSQRT

;find square root of b²-4ac

FSTSW AX TEST AX,1

;test for invalid error

JZ ROOTS1 FCOMPP

;clear stack

JMP ROOTS2

;end

ROOTS1: FLD B1 FCHS FSUB ST,ST(1) FDIV ST,ST(2) FSTP R1 FLD B1 FCHS

;save root 1

FADD FDIVR FSTP R2 ROOTS2: .EXIT END

;save root 2

;PROCEDURE TO FIND LOG10 X=LOG (FIND LOG

10

10

2 * LOG 2 X

OF THE VALUE AT THE STACK TOP)

LOG10 PROC NEAR FLDLG2 FXCH ST,ST(1) FYL2X FLD ST(1) RET LOG10 ENDP

; ;Program to calculate gain in decibels =20 LOG10(VOUT/VIN) VOUT DD

100 DUP(?)

VIN

DD

100 DUP(?)

DBG

DD

100 DUP(?)

TWEN DD GAIN

20.0

PROC NEAR LEA EBX,VOUT-4 LEA EDX,VIN-4 LEA ESI,DBG-4 MOV ECX,100

AGAIN: FLD DWORD PTR [EBX+4*ECX]

FDIV DWORD PTR [EDX+4*ECX] CALL LOG10 FMUL TWEN FSTP DWORD PTR [ESI+4*ECX] LOOPD AGAIN RET GAIN ENDP

Related Documents

Fpu
November 2019 9
Fpu Internals
November 2019 12