NUMERIC PROGRAMMING EXAMPLES

iAPX286 MACRO ASSEMBLER

80287

LaC

OBJ

LINE

002F

ODDS

113

11'

0031

09E8

115

0033

C3

116

 

 

117

 

 

118

 

 

120

 

 

".

0034

 

121

 

122

0034

09E5

123

12.

0036 'rOOFED

125

0039 2E082EOOOO

126

003E

9E

127

003F

7249

128

 

 

12.

 

 

130

 

 

131

0041

D9C9

132

0043

13100

133

0045

7Ee7

13.

 

 

135

 

 

136

 

 

137

 

 

138

 

 

13.

 

 

140

 

 

141

 

 

142

 

 

"3

T'I'ignometric Functions

 

10: 13: 51 09/25/83 PAGE

SOURCE

 

 

 

fstp

stCO)

Remove

a

fld 1

 

Return

1

rot

 

 

 

All ",ork is done as a sine function. By adding PI/2 to the angle

a cosine is converted to a sine. Of c:ourse the angle addition is not done to the argument but rather to the program logic control ",alues.

sine:

 

I

Entry

point

for sine

function

fXam

 

 

Look

at

the

parameter

 

fstsw

ax

 

Look

at

f!~am

status

 

 

f!ld

pi_quarter

 

Get

PI/4

",alue

 

 

 

sahf

 

 

CF

==

CO.

PF

::

C2. ZF

==

C3

J'

funnlJ-parameter

 

,Jump

if

emptlJ'

NAN.

or

infinity

Angle is unnormal. normal.

denormal.

 

 

 

 

 

fxch

cl,O

I

ST(1)

II:

PI/4,

steO)

angle

mov

;

Signal sine

 

 

 

 

Jpo

5 i ne_z ero_unnorma 1

; ,Jump if %ero or unnormal

ST(O) is either a normal or denormal ",alue. Both will work.

Use the fprem instruction to accuratellJ reduce the range of the gi",en

angle to within 0 and PI/4 in magnitude. If fprem cannot reduce the angle in one shot, the angle is too big to be meaningful, > 2*".62

radians. Any roundoff error in the calculation of the angle given

could completellJ change the result of this function. It is safE'st to call this verlJ rare c:ase an E'rror.

0047

 

144

0047

D9FB

145

 

 

146

 

 

147

 

 

148

 

 

14.

0049

93

150

151

004A

9BDFEO

152

0040

93

153

154

004E

F6C704

155

0051

7544

156

 

 

157

enter _sine:

fprem

 

xchg

ax. b x

fstsw

ax

xchg

ax. b x

test

bh, high(mask cond2l

Jnz

angle_too_big

IReduce angle

Note that fprem will force a

Idenormal to a verlJ small unnormal Fptan of a very small unnormal will be the same very small unnormal. which is correct.

Save old status in EX

Check if reduction was complete

IQuotient in CO. C3. Cl Put new status in bx

=sin(x)sin(2*N*PI+~)

 

 

158

 

 

15.

 

 

160

 

 

161

0053

09El

162

163

0055

OAe9

164

165

0057

740F

166

 

 

167

 

 

168

 

 

16.

 

 

170

0059 eOE4FD

171

172

Dose

BOeFBQ

173

 

 

174

005F

80C74Q

175

176

0062

BODO

177

0064

Dono

178

0066

32F8

179

 

 

180

 

 

181

 

 

182

 

 

183

 

 

184

0068

 

185

0068

F6C102

186

187

006B

7404

188

 

 

18.

 

 

,.0

0060

DEE9

",.2

OOoF EBCE

,.3

 

 

,I..5'

 

 

,.6

 

 

,.7

0071

 

,.8

0071

09E4

200

0073

91

'"

201

0074

9BDFEO

202

0077

91

203

0078

0009

204

007A

F6C540

205

0070

7514

206

Set sign flags and test for whic:h eighth of the revolution the angle fell into

Assert· -PI/4 < st(O) < PI/4

fabs

Force the al'gument positive

 

 

cond1 bit in bx holds the sign

Dr

cLcl

Test for sine Ol' cosine function

J'

sine_select

,Jump if sine function

 

 

 

This is a cosine function.

Ignol'e the origlnal sign of the angle

and add a G.uarter revolution to the octant id from the fpl'em instruction. cos (A) :::: sin(A+PI/2) and c:os( :A:) :::: cosCA)

and

ah,not high(mask condll

Turn Off sign of argument

 

bh, SOH

Prepare

to add

010 to CO, C3, Cl

 

 

status

value in

ax

 

bh, high (mask con(3)

Set busy bit so carry out from

add

C3 will go into the carry flag

mov

a}, 0

Extract

carrlJ flag

rol

al,l

Put carrlJ flag in low bit

 

bh, al

Add carry to CO not changing

 

 

Cl flag

 

 

See if the argument should be revel'sed, depending on the octant in which the argument fell during fprem.

test

bh, high(mask condU

 

J Reverse angle if' Cl

 

 

 

 

 

Angle was in oct nt~ 1.3....

5,7.

 

 

fsub

 

 

 

Invert

sense of rotation

Jmp

 

 

 

o < arg

<= PI/4

Angle was in octants 0,2,4,6.

Test for a zero aT'gument since fptan will not WOT'k if st(O) :::: 0

ftst

 

Test for

zero

angle

xchg

ax, cx

c,c'ind3

= 1

if'

st(Q) = 0

fstsw

ax

xchg

ax, c x

 

 

 

 

fstp

st( 1)

Remove

PI/4

 

te~t

ch,high(mask cond3)

I If C3==1. argument is zero

Jnz

sine_argument_zero

 

 

 

 

Figure 4-7. Calculating Trigonometric Functions (Cont'd.)

4-20

Page 476
Image 476
Intel 80287, 80286 manual Arg