32 divide
Richard,
After posting my rather unhelpful message, I had a longer think about the
problem of 32 bit / 16 bit signed division and have come up with the
following routine which seems to work. I haven't tested it thoroughly, and
if you want to use it, it's up to you to check it properly first.
I hope this is what you wanted.
test move.l #-10000000,d0
move.l #30,d1
bsr.s divide
rts
;; The following routine divides the signed 32-bit value in D0 by ;; the
signed 16-bit value in D1, returning the signed 32-bit ;; result in D0 and
the remainder in D1. ;; No other registers are affected
divide movem.l d2/d3/d4,-(a7)
moveq #0,d2 D2 holds the sign of the result
btst #31,d0
beq.s 2$
neg.l d0
moveq #1,d2 2$ btst #31,d1
beq.s 4$
neg.l d1
eor.b #1,d2 ;; Now do an unsigned divide 4$ move.l d0,d3
move.w #0,d3
swap d3
divu d1,d3 D3 = quotient / 2^16
move.w d3,d4
swap d4 high word of quotient
move.w d0,d3
divu d1,d3 divide D1 into (D0 – (D0/D1)*2^16)
move.w d3,d4
move.w #0,d3 get remainder…
swap d3
move.w d3,d1 … to D1
move.l d4,d0 ;; Adjust the sign
tst.b d2
beq.s 10$
neg.l d0 10$ movem.l (a7)+,d2/d3/d4
rts
Regards,
Shraddhan – via Whap! from Hertfordshire in the UK