Motorola DSP56800 Manual page 203

16-bit digital signal processor
Table of Contents

Advertisement

; Four-Quadrant Division of Fractional, Signed Data (B1:B0 / X0)
; Generates signed quotient and remainder
; Setup
MOVE
MOVE
ABS
EOR
BFCLR
; Division
REP
DIV
; Correct quotient
TFR
BGE
NEG
QDONE
MOVE
MOVE
ABS
ADD
BRCLR
MOVE
NEG
DONE
; Four-Quadrant Division of Integer, Signed Data (B1:B0 / X0)
; Generates signed quotient and remainder
; Setup
ASL
MOVE
MOVE
ABS
EOR
BFCLR
;Division
REP
DIV
; Correct quotient
TFR
BGE
NEG
QDONE
MOVE
MOVE
ABS
ADD
BRCLR
MOVE
NEG
ASR
DONE
B1,A
;Save sign bit of dividend (B1) in MSB of A1
B1,N
;Save sign bit of dividend (B1) in MSB of N
B
;Force dividend positive
X0,Y1
;Save sign bit of quotient in N bit of SR
#$0001,SR
;Clear carry bit: required for first DIV instruction
16
X0,B
B,A
QDONE
;If correct result is positive, then done
B
; Else negate to get correct negative result
A0,Y1
;Y1 <- True quotient
X0,A
;A <- Signed divisor
A
;A <- Absolute value of divisor
B,A
;A1 <- Restored remainder
#$8000,N,DONE
#0,A0
A
;(At this point, the correctly signed
; quotient is in Y1 and the correct
; remainder in A1)
B
;Shift of dividend required for integer
; division
B1,A
;Save sign bit of dividend (B1) in MSB of A1
B1,N
;Save sign bit of dividend (B1) in MSB of N
B
;Force dividend positive
X0,Y1
;Save sign bit of quotient in N bit of SR
#$0001,SR
;Clear carry bit: required for first DIV instruction
16
X0,B
B,A
QDONE
;If correct result is positive, then done
B
; Else negate to get correct negative result
A0,Y1
;Y1 <- True quotient
X0,A
;A <- Signed divisor
A
;A <- Absolute Value of divisor
B,A
;A1 <- Restored remainder
#$8000,N,DONE
#0,A0
A
B
;Shift required for correct integer remainder
;(At this point, signed quotient in Y1, correct
; remainder in A1)
Software Techniques
Division
8-17

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents