2009-11-04 18:23:40 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2009-11-04
|
|
|
|
;
|
|
|
|
; CC65 runtime: 32by16 => 16 unsigned division
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export udiv32by16r16, udiv32by16r16m
|
2009-11-04 19:41:54 +00:00
|
|
|
|
|
|
|
.include "zeropage.inc"
|
2009-11-04 18:23:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------------
|
|
|
|
; 32by16 division. Divide ptr1:ptr2 by ptr3. Result is in ptr1, remainder
|
|
|
|
; in sreg.
|
|
|
|
;
|
|
|
|
; lhs rhs result result also in remainder
|
|
|
|
; -----------------------------------------------------------------------
|
|
|
|
; ptr1:ptr2 ptr3 ax ptr1 sreg
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
udiv32by16r16:
|
|
|
|
sta ptr3
|
|
|
|
stx ptr3+1
|
|
|
|
udiv32by16r16m:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
sta sreg+1
|
|
|
|
ldy #32
|
2009-11-04 18:23:40 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
L0: asl ptr1
|
2009-11-04 18:23:40 +00:00
|
|
|
rol ptr1+1
|
|
|
|
rol ptr2
|
|
|
|
rol ptr2+1
|
|
|
|
rol a
|
|
|
|
rol sreg+1
|
|
|
|
|
2019-02-28 16:30:34 +00:00
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
cmp ptr3
|
|
|
|
lda sreg+1
|
|
|
|
sbc ptr3+1
|
|
|
|
bcc L1
|
|
|
|
|
|
|
|
sta sreg+1
|
2019-02-28 16:30:34 +00:00
|
|
|
txa
|
2013-05-09 11:56:54 +00:00
|
|
|
sbc ptr3
|
2019-02-28 16:30:34 +00:00
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
inc ptr1
|
|
|
|
|
2019-02-28 16:30:34 +00:00
|
|
|
L1: txa
|
2013-05-09 11:56:54 +00:00
|
|
|
dey
|
|
|
|
bne L0
|
|
|
|
sta sreg
|
2009-11-04 18:23:40 +00:00
|
|
|
lda ptr1
|
|
|
|
ldx ptr1+1
|
2013-05-09 11:56:54 +00:00
|
|
|
rts
|
2009-11-04 18:23:40 +00:00
|
|
|
|