Hitachi H8/300H Series Programming Manual page 96

Table of Contents

Advertisement

DIVXS
DIVXS (DIVide eXtend as Signed)
2. Programming solution for DIVXS.W R0, ER1
Example: Convert dividend and divisor to non-negative numbers, then use DIVXU programming
solution for zero divide and overflow
MOV.W
R0, R0
BEQ
ZERODIV
ANDC
#AF, CCR
BPL
L1
NEG.W
R0
ORC
#10, CCR
L1: MOV.L
ER1,ER1
BPL
L2
NEG.L
ER1
XORC
#50,CCR
L2: MOV.W
E1, R2
EXTU.L
ER2
DIVXU.W
R0, E2
MOV.W
E2, R1
DIVXU.W
R0, ER1
MOV.W
R2, E2
MOV.W
R1, R2
STC
CCR, R1L
BTST
#6, R1L
BEQ
L3
NEG.W
E1
L3: BTST
#4, R1L
BEQ
L4
NEG.L
ER2
L4: RTS
ZERODIV:
This program leaves a 32-bit quotient in ER2 and a 16-bit remainder in E1.
ER1
E1
ER2
; Test divisor
; Branch to ZERODIV if R0 = 0
; Clear CCR user bits (bits 6 and 4) to 0
; Branch to L1 if N flag = 0 (positive divisor)
; Take 2's complement of R0 to make sign positive
; Set CCR bit 4 to 1
; Test dividend
; Branch to L2 if N flag = 0 (positive dividend)
; Take 2's complement of ER1 to make sign positive
; Invert CCR bits 6 and 4
;
;
;
Use DIVXU.W instruction to divide non-negative dividend
;
by positive divisor
32 bits ÷ 16 bits → quotient (32 bits) and remainder
;
(16 bits)
(See DIVXU Instruction, Zero Divide, and Overflow)
; Copy CCR contents to R1L
; Test CCR bit 6
; Branch to L3 if bit 6 = 1
; Take 2's complement of E1 to make sign of remainder negative
; Test CCR bit 4
; Branch to L4 if bit 4 = 1
; Take 2's complement of ER2 to make sign of quotient negative
; Zero-divide handling routine
R0
Dividend
Remainder
Quotient
88
Divisor
Divide Signed

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents