EasyManua.ls Logo

Texas Instruments TMS320C28x - Page 503

Texas Instruments TMS320C28x
695 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SUBCU ACC,loc16
6-346
Example 2
; Calculate signed: Quot16 = Num16Den16, Rem16 = Num16%Den16
CLRC TC ; Clear TC flag, used as sign flag
MOV ACC,@Den16 << 16 ; AH = Den16, AL = 0
ABSTC ACC ; Take abs value, TC = sign ^ TC
MOV T,@AH ; Temp save Den16 in T register
MOV ACC,@Num16 << 16 ; AH = Num16, AL = 0
ABSTC ACC ; Take abs value, TC = sign ^ TC
MOVU ACC,@AH ; AH = 0, AL = Num16
RPT #15 ; Repeat operation 16 times
||SUBCU ACC,@T ; Conditional subtract with Den16
MOV @Rem16,AH ; Store remainder in Rem16
MOV ACC,@AL << 16 ; AH = Quot16, AL = 0
NEGTC ACC ; Negate if TC = 1
MOV @Quot16,AH ; Store quotient in Quot16
Example 3
; Calculate unsigned: Quot32 = Num32/Den16, Rem16 = Num32%Den16
MOVU ACC,@Num32+1 ; AH = 0, AL = high 16-bits of Num32
RPT #15 ; Repeat operation 16 times
||SUBCU ACC,@Den16 ; Conditional subtract with Den16
MOV @Quot32+1,AL ; Store high 16-bit in Quot32
MOV AL,@Num32+0 ; AL = low 16-bits of Num32
RPT #15 ; Repeat operation 16 times
||SUBCU ACC,@Den16 ; Conditional subtract with Den16
MOV @Rem16,AH ; Store remainder in Rem16
MOV @Quot32+0,AL ; Store low 16-bit in Quot32
Example 4
; Calculate signed: Quot32 = Num32/Den16, Rem16 = Num32%Den16
CLRC TC ; Clear TC flag, used as sign flag
MOV ACC,@Den16 << 16 ; AH = Den16, AL = 0
ABSTC ACC ; Take abs value, TC = sign ^ TC
MOV T,@AH ; Temp save Den16 in T register
MOVL ACC,@Num32 ; ACC = Num32
ABSTC ACC ; Take abs value, TC = sign ^ TC
MOV P,@ACC ; P = Num32
MOVU ACC,@PH ; AH = 0, AL = high 16-bits of Num32
RPT #15 ; Repeat operation 16 times
||SUBCU ACC,@T ; Conditional subtract with Den16
MOV @Quot32+1,AL ; Store high 16-bit in Quot32
MOV AL,@PL ; AL = low 16-bits of Num32
RPT #15 ; Repeat operation 16 times
||SUBCU ACC,@T ; Conditional subtract with Den16
MOV @Rem16,AH ; Store remainder in Rem16
MOV ACC,@AL << 16 ; AH = low 16-bits of Quot32, AL = 0
NEGTC ACC ; Negate if TC = 1
MOV @Quot32+0,AH ; Store low 16-bit in Quot32

Table of Contents

Related product manuals