beautypg.com

Motorola DSP96002 User Manual

Page 709

background image

B-190

DSP96002 USER’S MANUAL

MOTOROLA

dec d1 ;and adjust exponent

_startdiv

move d1.l,x:(r0) ;save new exponent

;

; unsigned fractional divide: d7:d6 / d5:d4 = d3:d2

;

do #64,_divloop

cmp d5,d7 ;compare ms word

jhi _big ;dividend > divisor

jlo _small ;dividend < divisor

cmp d4,d6 ;compare ls word

jhs _big ;dividend >= divisor

_small andi #$fe,ccr ;set 0 q bit

jmp _q

_big sub d4,d6 ;adjust remainder

subc d5,d7

ori #$01,ccr ;set 1 q bit

_q rol d2 ;move in q bit

rol d3

lsl d6 ;adjust remainder

rol d7

_divloop move d3.l,x:(r0+ms) ;save ms

move d2.l,x:(r0+ls) ;save ls

move x:(r0+sign),d0.l ;get sign

move x:(r1+sign),d1.l ;get sign

eor d1,d0 ;new sign

move d0.l,x:(r0+sign) ;save sign

jmp echeck ;check for errors

;

; MOTOROLA DSP96002 DPLIB - VERSION 1.0
;
; DP_INT - Truncate a double precision number to an integer.

;

; Entry point: dp_int: c(r0)

truncate to integer

c(r0)

;

; Inputs: r0 contains the lowest address of a 4-word internal

; extended precision number

;

; Outputs: r0 contains the lowest address of a 4-word internal

; extended precision number

;

; Alters: D2.L,D3.L,D4.L,D7.L,D0.H

;

dp_int move x:(r0),d4.l ;get exponent

move #bias,d7.l ;get bias

sub d7,d4 #64,d2.l ;calculate how far to shift

jmi dp_clr ;if a fraction, zero the number

cmp d2,d4 #32,d2.l ;is A > 2**63

jpl aequala ;yes, out of range

cmp d2,d4 #$80000000,d3.l ;is A > 2**31

jpl rndls ;yes, last valid digit is in ls

clr d1.l d4.l,d0.h ;no, put # shifts in .h register

asr d0,d3 x:(r0+ms),d0.l ;zero ls, create trunc. mask