A83: Signed Division


[Prev][Next][Index][Thread]

A83: Signed Division




I am writing a program for the 83+ that uses signed division. I decided
against using the OPx ROM calls for this becuase they are floating point
and presumably quite slow. I used to have four or five lines of code to
handle my unsigned division, the signed routine is huge by comparison. I
found a signed division routine on the 'net', but I'm wondering how
efficient it is. I don't understand how it works, I just assume that it
does. Is this routine (below) any good, can anybody point me the
direction of a better faster one...?

--Robin Kay--

Div:               ; HL=BC/DE,AF=0,BC=0,DE=0
 ld a,d
 or e
 scf
 ret z
 xor a
 bit 7,b
 jr z,div3
 inc a
 ld hl,0
 sbc hl,bc
 ld b,h
 ld c,l
div3:
 bit 7,d
 jr z,div4
 inc a
 ld hl,0
 sbc hl,de
 ld d,h
 ld e,l
div4:
 ld h,b
 ld l,c
 ld bc,0
DivLoop:
 or a
 sbc hl,de
 jr c,FixSign
 inc bc
 jr DivLoop
FixSign:
 ld h,b
 ld l,c
 or a
 res 7,h
 bit 0,a
 ret z
 ld hl,0
 sbc hl,bc
 or a
 ret




Follow-Ups: