;

; tmp2=tmp2/tmp (32-bit signed)

;

div

lda tmp+3;dividend sign

eor tmp2+3

pha;sign of quotient

lda tmp+3;test sign of xy

bpl div1

sec

lda #0

sbc tmp

sta tmp

lda #0

sbc tmp+1

sta tmp+1

lda #0

sbc tmp+2

sta tmp+2

lda #0

sbc tmp+3

sta tmp+3

div1

lda tmp2+3;test sign of xy

bpl div2

sec

lda #0

sbc tmp2

sta tmp2

lda #0

sbc tmp2+1

sta tmp2+1

lda #0

sbc tmp2+2

sta tmp2+2

lda #0

sbc tmp2+3

sta tmp2+3

div2

jsr udiv;unsigned divide

pla;sign of quotient

bpl div3

sec

lda #0

sbc tmp2

sta tmp2

lda #0

sbc tmp2+1

sta tmp2+1

lda #0

sbc tmp2+2

sta tmp2+2

lda #0

sbc tmp2+3

sta tmp2+3

div3

rts

;

; tmp2=tmp2/tmp (32-bit unsigned)

;

udiv

lda tmp

ora tmp1

ora tmp2

ora tmp3

beq zerodiv

lda #0

sta tmp1

sta tmp1+1

sta tmp1+2

sta tmp1+3

ldx #32

asl tmp2

rol tmp2+1

rol tmp2+2

rol tmp2+3

udiv2

rol tmp1

rol tmp1+1

rol tmp1+2

rol tmp1+3

sec

lda tmp1

sbc tmp

sta tmp3

lda tmp1+1

sbc tmp+1

sta tmp3+1

lda tmp1+2

sbc tmp+2

sta tmp3+2

lda tmp1+3

sbc tmp+3

bcc udiv3

sta tmp1+3

lda tmp3+2

sta tmp1+2

lda tmp3+1

sta tmp1+1

lda tmp3

sta tmp1

udiv3

rol tmp2

rol tmp2+1

rol tmp2+2

rol tmp2+3

dex

bne udiv2

rts

zerodiv

ldx #$85

jmp $C47E

;

; tmp2=tmp2 % tmp (32-bit signed)

;

mod

lda tmp+3;dividend sign

eor tmp2+3

pha;sign of quotient

lda tmp+3;test sign of xy

bpl mod1

sec

lda #0

sbc tmp

sta tmp

lda #0

sbc tmp+1

sta tmp+1

lda #0

sbc tmp+2

sta tmp+2

lda #0

sbc tmp+3

sta tmp+3

mod1

lda tmp2+3;test sign of xy

bpl mod2

sec

lda #0

sbc tmp2

sta tmp2

lda #0

sbc tmp2+1

sta tmp2+1

lda #0

sbc tmp2+2

sta tmp2+2

lda #0

sbc tmp2+3

sta tmp2+3

mod2

jsr udiv;unsigned divide

pla;sign of quotient

bpl mod3

sec

lda #0

sbc tmp1

sta tmp1

lda #0

sbc tmp1+1

sta tmp1+1

lda #0

sbc tmp1+2

sta tmp1+2

lda #0

sbc tmp1+3

sta tmp1+3

mod3