This subroutine will divide 32-bit value at r19:r18:r17:R16 with 32-bit value at r23:r22:r21:R20. Result is 32-bit at
r19:r18:r17:R16 and remainder is at r19:r18:r17:R16.
This routine uses r27:r26:r25:r24 as temporary registers.
(r19:r18:r17:R16)
(r23:r22:r21:R20)
-----------------:
(r19:r18:r17:R16) remainder: (r23:r22:r21:R20)
div32by32:
clr r25
tst r23
breq udi10
ldi r24, 8
udi1: lsl r16
rol r17
rol r18
rol r19
rol r25
cp r17, r20
cpc r18, r21
cpc r19, r22
cpc r25, r23
brcs udi2
sub r17, r20
sbc r18, r21
sbc r19, r22
sbc r25, r23
inc r16
udi2: dec r24
brne udi1
mov r20, r17
clr r17
mov r21, r18
clr r18
mov r22, r19
clr r19
mov r23, r25
ret
udi10: tst r22
breq udi20
ldi r24, 16
udi11: lsl r16
rol r17
rol r18
rol r19
rol r25
brcs udi12
cp r18, r20
cpc r19, r21
cpc r25, r22
brcs udi13
udi12: sub r18, r20
sbc r19, r21
sbc r25, r22
inc r16
udi13: dec r24
brne udi11
mov r20, r18
clr r18
mov r21, r19
clr r19
mov r22, r25
ret
udi20: tst r21
breq udi30
ldi r24, 24
udi21: lsl r16
rol r17
rol r18
rol r19
rol r25
brcs udi22
cp r19, r20
cpc r25, r21
brcs udi23
udi22: sub r19, r20
sbc r25, r21
inc r16
udi23: dec r24
brne udi21
mov r20, r19
clr r19
mov r21, r25
ret
udi30: ldi r24, 32
udi31: lsl r16
rol r17
rol r18
rol r19
rol r25
brcs udi32
cp r25, r20
brcs udi33
udi32: sub r25, r20
inc r16
udi33: dec r24
brne udi31
mov r20, r25
ret
No comments:
New comments are not allowed.