Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
46
Добавлен:
27.04.2015
Размер:
4.26 Mб
Скачать

Incrementing and Decrementing Operations

8.3 Incrementing and Decrementing Operations

Almost any piece of data can be incremented or decremented. This section summarizes the different increments and decrements available to both registers and memory locations. It is important to note the LEA instruction, which is used to increment or decrement AGU pointer registers. The TSTW instruction is also used for decrementing AGU pointer registers. This instruction is similar to LEA but also sets the condition codes, making it useful for program looping and other tasks. The LEA and TSTW instructions do not cause a pipeline dependency in the AGU (see Section 4.4, “Pipeline Dependencies,” on page 4-33). The TSTW instruction is not available for incrementing an AGU pointer or for decrementing the SP register.

; Different ways to increment on the DSP56800 core

INCW

A

; on a Data ALU Accumulator

INCW

X0

; on a Data ALU Input Register

LEA

(Rn)+

; on an AGU pointer register (R0-R3 or SP)

INCW

X:$0

; on anywhere within the first 64 locations

 

 

; of X data memory

INCW

X:$C200

; on anywhere within the entire 64K locations

 

 

; of X data memory

INCW

X:(SP-37)

; on a value located on the stack

; Different ways to decrement on the DSP56800 core

DECW

A

; on a Data ALU Accumulator

DECW

X0

; on a Data ALU Input Register

LEA

(Rn)-

; on an AGU pointer register (R0-R3 or SP)

TSTW

(Rn)-

; on an AGU pointer register (R0-R3)

DECW

X:$0

; on anywhere within the first 64 locations

 

 

; of X data memory

DECW

X:$C200

; on anywhere within the entire 64K locations

 

 

; of X data memory

DECW

X:(SP-37)

; on a value located on the stack

The many different techniques available help to prevent registers from being destroyed. Otherwise, as found on other architectures, it is necessary to first move data to an accumulator to perform an increment.

8.4 Division

It is possible to perform fractional or integer division on the DSP56800 core. There are several questions to consider when implementing division on the DSP core:

Are both operands always guaranteed to be positive?

Are operands fractional or integer?

Is only the quotient needed, or is the remainder needed as well?

Will the calculated quotient fit in 16 bits in integer division?

Are the operands signed or unsigned?

How many bits of precision are in the dividend?

What about overflow in fractional and integer division?

Will there be “integer division” effects?

NOTE:

In a division equation, the “dividend” is the numerator, the “divisor” is the denominator, and the “quotient” is the result.

 

Software Techniques

8-13

Software Techniques

Once all these questions have been answered, it is possible to select the appropriate division algorithm. The fractional algorithms support a 32-bit signed dividend, and the integer algorithms support a 31-bit signed dividend. All algorithms support a 16-bit divisor.

Note that the most general division algorithms are the fractional and integer algorithms for four-quadrant division that generate both a quotient and a remainder. These take the largest number of instruction cycles to complete and use the most registers.

For extended precision division, where the number of quotient bits required is more than 16, the DIV instruction and routines presented in this section are no longer applicable. For further information on division algorithms, consult the following references (or others as required):

Theory and Application of Digital Signal Processing, Lawrence R. Rabiner and Bernard Gold (Prentice-Hall: 1975), pages 524–530.

Computer Architecture and Organization, John Hayes (McGraw-Hill: 1978), pages 190–199.

8.4.1 Positive Dividend and Divisor with Remainder

The algorithms in the following code are the fastest and take the least amount of program memory. In order to use these algorithms, it must be guaranteed that both the dividend and divisor are both positive, signed, two’s-complement numbers. One algorithm is presented for the division of fractional numbers and a second is presented for the division of integer numbers. Both algorithms generate the correct positive quotient and positive remainder.

; Division of Fractional, Positive Data (B1:B0 / X0)

BFCLR

#$0001,SR

; Clear carry bit: required for first DIV

REP

16

 

DIV

X0,B

;Form positive quotient in B0

ADD

X0,B

;Restore remainder in B1

 

 

;(At this point, the positive quotient is

;in B0 and the positive remainder is in B1)

;Division of Integer, Positive Data (B1:B0 / X0)

ASL

B

;Shift of dividend required for integer

 

 

; division

BFCLR

#$0001,SR

;Clear carry bit: required for first DIV

REP

16

 

DIV

X0,B

;Form positive quotient in B0

MOVE

B0,Y1

;Save quotient in Y1

 

 

;(At this point, the positive quotient is in

 

 

; B0 but the remainder is not yet correct)

ADD

X0,B

;Restore remainder in B1

ASR

B

;Required for correct integer remainder

 

 

;(At this point, the correct positive

 

 

; remainder is in B1)

8-14

DSP56800 Family Manual

 

Division

8.4.2 Signed Dividend and Divisor with No Remainder

The algorithms in the following code provide fast ways to divide two signed, two’s-complement numbers. These algorithms are faster because they generate the quotient only; they do not generate a correct remainder. The algorithms are referred to as four-quadrant division because they allow any combination of positive or negative operands for the dividend and divisor. One algorithm is presented for the division of fractional numbers, and a second is presented for the division of integer numbers.

;4 Quadrant Division of Fractional, Signed Data (B1:B0 / X0)

;Generates signed quotient only, no remainder

;Setup

MOVE

B,Y1

;Save Sign Bit of dividend (B1) in MSB of Y1

ABS

B

;Force dividend positive

EOR

X0,Y1

;Save sign bit of quotient in N bit of SR

BFCLR

#$0001,SR

;Clear carry bit: required for 1st DIV instr

; Division

 

 

REP

16

 

DIV

X0,B

;Form positive quotient in B0

; Correct quotient

 

 

BGE

DONE

;If correct result is positive, then done

NEG

B

;Else negate to get correct negative result

DONE

 

;(At this point, the correctly signed

 

 

;quotient is in B0 but the remainder is not

;correct)

;4 Quadrant Division of Integer, Signed Data (B1:B0 / X0)

;Generates signed quotient only, no remainder

;Setup

ASL

B

;Shift of dividend required for integer

 

 

; division

MOVE

B,Y1

;Save Sign Bit of dividend (B1) in MSB of Y1

ABS

B

;Force dividend positive

EOR

X0,Y1

;Save sign bit of quotient in N bit of SR

BFCLR

#$0001,SR

;Clear carry bit: required for 1st DIV instr

; Division

 

 

REP

16

 

DIV

X0,B

;Form positive quotient in B0

; Correct quotient

 

 

BGE

DONE

;If correct result is positive, then done

NEG

B

;Else negate to get correct negative result

DONE

 

;(At this point, the correctly signed

 

 

 

 

; quotient is in B0 but the remainder is not

 

 

; correct)

 

Software Techniques

8-15

Software Techniques

8.4.3 Signed Dividend and Divisor with Remainder

The algorithms in the following code are another way to divide two signed numbers, where both the dividend or the divisor are signed two’s-complement numbers (positive or negative). These algorithms are the most general because they generate both a correct quotient and a correct remainder. The algorithms are referred to as 4 quadrant division because these algorithms allow any combination of positive or negative operands for the dividend and divisor. One algorithm is presented for division of fractional numbers and a second is presented for the division of integer numbers.

8-16

DSP56800 Family Manual

 

Division

;Four-Quadrant Division of Fractional, Signed Data (B1:B0 / X0)

;Generates signed quotient and remainder

;Setup

MOVE

B1,A

;Save sign bit of dividend (B1) in MSB of A1

MOVE

B1,N

;Save sign bit of dividend (B1) in MSB of N

ABS

B

;Force dividend positive

EOR

X0,Y1

;Save sign bit of quotient in N bit of SR

BFCLR

#$0001,SR

;Clear carry bit: required for first DIV instruction

; Division

 

 

REP

16

 

DIV

X0,B

 

; Correct quotient

 

 

TFR

B,A

 

BGE

QDONE

;If correct result is positive, then done

NEG

B

; Else negate to get correct negative result

QDONE

 

 

MOVE

A0,Y1

;Y1 <- True quotient

MOVE

X0,A

;A <- Signed divisor

ABS

A

;A <- Absolute value of divisor

ADD

B,A

;A1 <- Restored remainder

BRCLR

#$8000,N,DONE

 

MOVE

#0,A0

 

NEG

A

 

DONE

 

;(At this point, the correctly signed

 

 

;quotient is in Y1 and the correct

;remainder in A1)

;Four-Quadrant Division of Integer, Signed Data (B1:B0 / X0)

;Generates signed quotient and remainder

;Setup

ASL

B

 

;Shift of dividend required for integer

 

 

 

; division

MOVE

B1,A

 

;Save sign bit of dividend (B1) in MSB of A1

MOVE

B1,N

 

;Save sign bit of dividend (B1) in MSB of N

ABS

B

 

;Force dividend positive

EOR

X0,Y1

 

;Save sign bit of quotient in N bit of SR

BFCLR

#$0001,SR

;Clear carry bit: required for first DIV instruction

;Division

 

 

 

REP

16

 

 

DIV

X0,B

 

 

; Correct quotient

 

 

 

TFR

B,A

 

 

BGE

QDONE

 

;If correct result is positive, then done

NEG

B

 

; Else negate to get correct negative result

QDONE

 

 

 

MOVE

A0,Y1

 

;Y1 <- True quotient

MOVE

X0,A

 

;A <- Signed divisor

ABS

A

 

;A <- Absolute Value of divisor

ADD

B,A

 

;A1 <- Restored remainder

BRCLR

#$8000,N,DONE

 

MOVE

#0,A0

 

 

NEG

A

 

 

ASR

B

;Shift required for correct integer remainder

DONE

 

 

 

;(At this point, signed quotient in Y1, correct ; remainder in A1)

 

Software Techniques

8-17

Соседние файлы в папке DSP568xx