0 Members and 3 Guests are viewing this topic.
;===============================================================HL_Div_BC_Signed:;===============================================================;Performs HL/BC;Speed: 1350-55a-2b; b is the number of set bits in the result; a is the number of leading zeroes in the absolute value of HL, minus 1; add 24 if HL is negative; add 19 if BC is negative; add 28 if the result is negative ;Size: 68 bytes;Inputs:; HL is the numerator; BC is the denominator;Outputs:; DE is the quotient; HL is the remainder; BC is not changed;Destroys:; A;=============================================================== ld a,h xor b push af;absHL xor b jp p,$+9 xor a \ sub l \ ld l,a sbc a,a \ sub h \ ld h,a;absBC: bit 7,b jr z,$+8 xor a \ sub c \ ld c,a sbc a,a \ sub b \ ld b,a ld de,0 adc hl,hl jr z,EndSDiv ld a,16 add hl,hl dec a jp nc,$-2 ex de,hl jp jumpinLoop1: add hl,bc ;--Loop2: dec a ;4 jr z,EndSDiv ;12|23 sla e ;-- rl d ;--jumpin: ; adc hl,hl ;15 sbc hl,bc ;15 jr c,Loop1 ;23-2b ;b is the number of bits in the absolute value of the result. inc e ;-- jp Loop2 ;--EndSDiv: pop af \ ret p xor a \ sub e \ ld e,a sbc a,a \ sub d \ ld d,a ret