1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-30 12:28:25 +00:00
cc65/libsrc/runtime/idiv32by16r16.s
uz 18272c0427 Working on the division and multiplication routines.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4443 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-11-04 19:41:54 +00:00

65 lines
1.3 KiB
ArmAsm

;
; Ullrich von Bassewitz, 2009-11-04
;
; CC65 runtime: 32by16 => 16 signed division
;
.export idiv32by16r16
.import negax, udiv32by16r16m
.include "zeropage.inc"
;---------------------------------------------------------------------------
; 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
;
idiv32by16r16:
stx tmp1
cpx #0
bpl @L1
jsr negax
@L1: sta ptr3
stx ptr3+1
lda ptr2+1
eor tmp1
sta tmp1
bit ptr2+1
bpl @L3
; Negate the value in ptr1:ptr2
ldx #0
ldy #4
sec
@L2: lda ptr1,x
eor #$FF
adc #$00
sta ptr1,x
inx
dey
bne @L2
; Call the unsigned division routine
@L3: jsr udiv32by16r16m
; Check the sign of the result
bit tmp1
bmi @L4
rts
; Negate the result. We do this here only for the result, not for the
; remainder!
@L4: jmp negax