Working on the division and multiplication routines.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4443 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2009-11-04 19:41:54 +00:00
parent 655ba3e6ee
commit 18272c0427
11 changed files with 155 additions and 24 deletions

View File

@@ -81,6 +81,7 @@ OBJS = add.o \
ge.o \
gt.o \
icmp.o \
idiv32by16r16.o \
imul16x16r32.o \
incax1.o \
incax2.o \

View File

@@ -0,0 +1,64 @@
;
; 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

View File

@@ -6,7 +6,8 @@
.export imul16x16r32
.import negax, umul16x16r32m, negeax
.importzp ptr1, ptr3, tmp1
.include "zeropage.inc"
;---------------------------------------------------------------------------

View File

@@ -5,7 +5,8 @@
;
.export udiv32by16r16, udiv32by16r16m
.importzp ptr1, ptr2, ptr3, sreg
.include "zeropage.inc"
;---------------------------------------------------------------------------

View File

@@ -5,7 +5,8 @@
;
.export umul16x16r32, umul16x16r32m
.importzp ptr1, ptr3, sreg
.include "zeropage.inc"
;---------------------------------------------------------------------------