NUMERIC PROGRAMMING EXAMPLES

iAPX2B6 MACRO ASSEMBLER

Loe OBJ

0083 09F4

0085 80FAFB

0088 7240

OOBA eOEAFB

0080 09E8

DoeF

DoeF DCC1 0091 DEE9

0093 D9F4

0095 D9C9

0097 OF15

0099 DEC;!

Q09Il F71D

009D 7529

009F D9C9

aOA1 OFID

aOA3 80EAF8

OOA6 E9A400

OOA9

OOA9 BOEAFC

()OAC E99EOO

aOAF

DOAF 09E8

OOBl DC'1C9

00133 D9FB

00135 D9F4

aaB7 09£5

0099 9BDFEO

COBe 09C9

DaDE D9CA

aOCD BOEAFA

aOC::3 1090044

aOC6 74C7

Dace ODDS

aOCA

aOCA

OOCA CB7EFO

OOCD OF56FC

0000 D9Ee

0002 DEe9

0004 DF5EFA

80287

Floating-Point to

IS-Digit ASCII Conversion

10: 12: 89 09/25/83 PAGE

LINE

SOURCE

 

 

 

228

fxtratt

 

J Separate exponent f'T'om significand

22.

cmp

dl,UNNDRMAL

,

Test for unnormal value

230

Jb

normal_value

 

 

231

sub

d 1, UNNORMAL-NORMAL

 

Return normal status with correct Sign

232

 

233

234Normalize the fraction. adJust the power of two in ST(1) and 1t.et

235the denormal count value.

236

Assert: 0 <'"ST(O) ( 1.0

 

237

 

238

-Fld 1

, Load constant to normalize fraction

239

240

 

 

241norma 1 i z e_frac t ion:

243

fadd

st(1).1t.t

 

 

Set integer bit in fraction

24.

hub

 

 

j

Form normalized fraction in ST(O)

245

 

 

 

J

Power of two Held will be negative

246

f xc h

 

 

 

of denormal count

247

 

 

j

Put denormal count in ST(O)

248

fi1t.t

word ptr

CdiJ

J

Put negative of dl!'normal count in memorl,l

24'

faddp

st (2). st

 

 

Form correct power of two in stt!)

250

 

 

 

 

OK to use word ptr CdiJ now

251

ne-g

word ph

CdiJ

 

Form positive denormt!ll count

:?52

Jnz

not_psuedo_zero

 

 

253

 

 

 

 

 

254A psuedo zero will appear an unnormal numbeor. When attemptinll

255to normalia it. the resultant fraction field will be zero. Perfo~minll

256

an f'xtrBct on zero will yield a

zero exponent value.

.

257

 

 

) Put power of tllJO value in !OttO)

258

f~ch

 

259

Fistp

word ptr CdiJ

Set denorm<ll count to power of' two value

260

 

 

Word ph (diJ is not u!;ed by convert

261

 

 

integer. OK to letJve

running

262

!:tub

dl, NDRMAL-P5UEDO_ZERD

,Set return value saving thf! sign bit

263

Jmp

convert_i.nteger

) Put zero value into memory

264

 

 

 

 

265The number is a real zero. 'iet the return value and setup for

266conversion to BCD

267

268

 

 

 

 

269

d 1, ZERO-NORMAL

,

Convert <;t.3tlIS to

normal v<'Jlu!'

270

~71

convert_integer

i

Treat the: l~ro as

an i.ntE!geT'

27.

273Th. nUmbllr is a dllnoTmal. FXTRACT will not wOTk correctly in tht.

27.elutt. To corrttetlu slIparate the eKponllnt and fraction, add a fixed

275

J

constant to tht' exponent to guarantee thll rellult il not a denormal.

276

,

 

277found_d enorma 1:

27.

fld 1

j PTeparl! to. bump axponent

280

heh

ForeD denormal to smallelit represllntable

281

fpram

28.

 

utendlld raal -Format exponent

283

htract

) This will work corrllctly now

28.

The power of the original dllnoT'mal valu. n.n baen safely isohtad.

28.

286Check if the fraction value is an unnormal.

287

 

 

 

SII' if the fraction is an unnormal

288

ham

 

 

28.

htsw

 

 

Save 80287 statu. In CPU AX rIg for later

2'0

hch

 

I

Put

uponent

in 9T(O)

291

heh

atC:!)

,

Put

1. ~ into

SHO),

uponant in 9T(2)

2'2

"b

dl. DENORMAL-NORMAI..

j

Return normal status with correct lign

:293

t!!!!t

8K,4400H

j

See

if! C:3-C:!"O imp ling unnormal aT' NAN

2 ••

J'

norma 1 i :re_fTac t i on

j

Jump if -Fraction is an unnormal

29'

 

 

 

 

 

 

fstp

stCO)

 

Remov. unnecessary

1. 0 from lIteO)

2'6

j

2'7

2..8, Calculatt the d.eimal magnitude a"oelated with this numb Ill' to

lIIithin one order. Tnt. error lIIi1l allllays bll inevihbh due to

300rounding and lost pr.ttlion. A. a rlSult, we will delibarfttwly fail

301to considar the LOOIO of the fraction valua in calculating thll oT'dn.

302Since th hattion will alwaYI be 1 <- F <:!, its L.DOIO will not change

303thll baSic accurilcl/ oft the function. To get thll decimal order of magnitude.

30.limply multipl1J tha power of two bl,l L.OQ10(2) and truncate thll ruult to

30' , .an integar. 306

307normal_valu.:

308notJlIu.do_:rero:

30,

310

fltp

fTacUon

 

tlsve

,;;nll Tr.1;;~I.I;U' ii.."";

; ... , ~

311

fiat

POWtT'_two

 

Save

power of two

 

312

Udlg2

 

 

Qet

L.OQ10(2)

 

313

 

 

 

Pow.r_two is noUl saf. to us.

31.

fmul

 

I

Form LOG10(of exponent

of number)

31.

fhtp

power_tan

j

AnI,!

rounding moda will work harll

316

 

 

 

 

 

 

317Check if the magnitude of thll number rule. out treating it al

318integllr.

31.

320CX ha. the maximum number of decimal digits allowed.

Figure 4-6. Floating-Point to ASCII Conversion Routine (Cont'd.)

4-10

Page 466
Image 466
Intel 80287, 80286 manual DoeF