0 Members and 1 Guest are viewing this topic.
;###################################;div 24 by 24;bcd / ehl;ouput: ehl = quotient; bcd = remainderdivScratch equ $8000divBCDbyEHL: ld ix, divScratch ld (ix), d ld (ix+1), c ld (ix+2), b xor a ld (ix+3), a ld (ix+4), a ld (ix+5), a ld b, 24div24Loop: sla (ix) rl (ix+1) rl (ix+2) rl (ix+3) rl (ix+4) rl (ix+5) ld a, (ix+5) cp e jr c, notBigEnough jr nz, oversize ld a, (ix+4) cp h jr c, notBigEnough jr nz, oversize ld a, (ix+3) cp l jr c, notBigEnoughoversize: inc (ix) ld a, (ix+3) sub l ld (ix+3), a ld a, (ix+4) sbc a, h ld (ix+4), a ld a, (ix+5) sbc a, e ld (ix+5), a notBigEnough: djnz div24Loop ld l, (ix) ld h, (ix+1) ld e, (ix+2) ld d, (ix+3) ld c, (ix+4) ld b, (ix+5) ret
Div24by24: ld b,a ;INPUTS: ahl = dividend cde = divisor push hl ;OUTPUTS: cde = quotient ahl = remainder pop ix ld l,24 push hl xor a ld h,a ld l,a__Div24by24loop: add ix,ix rl b adc hl,hl rla cp c jr c,__Div24by24skip jr nz,__Div24by24setbit sbc hl,de add hl,de jr c,__Div24by24skip__Div24by24setbit: sbc hl,de sbc a,c inc ix__Div24by24skip: ex (sp),hl dec l ex (sp),hl jr nz,__Div24by24loop pop de ld c,b push ix pop de ret
But, if I know this forum, just wait a few hours and you'll have one half as big and twice as fast from calc84maniac Runer112.
I haven't tested it myself, but try this? It appears to me that it should work, and it doesn't require any scratch memory. And by my count, it's only 43 bytes.
Mul16by8: ex de,hl ;INPUTS: hl = multiplicand a = multiplier ld hl,0 ;OUTPUTS: ahl = product b = 0 ld b,8__Mul16by8loop: add hl,hl rla jr nc,__Mul16by8skip add hl,de adc a,0__Mul16by8skip: djnz __Mul16by8loop ret
Div24by16: push hl ;INPUTS: ahl = dividend de = divisor pop ix ;OUTPUTS: ahl = quotient de = divisor ld hl,0 ld b,24__Div24by16loop: add ix,ix rla adc hl,hl jr c,__Div24by16setbit or a sbc hl,de add hl,de jr c,__Div24by16skip__Div24by16setbit: or a sbc hl,de inc ix__Div24by16skip: djnz __Div24by24loop push ix pop hl ret