jacobly
LV4 Regular (Next: 200)
Offline
Last Login:
Yesterday at 21:01:13
Date Registered: 09 October, 2011, 01:53:09
Posts: 199
Total Post Ratings:
+149
«
Reply #30 on: 11 December, 2011, 21:06:55 »
0
1 2 3 4 5 6 7 8 9
// Multiply a times b temp = 0 repeat for each bit in a temp <<= 1 if (high bit of a set) temp += b a <<= 1 return temp
if a and b are 2 bytes, temp is 4 bytes, and you loop 16 times.
Spoiler for for code :
stolen from Axe p_MulFull: ; Input in hl, result in cahl ld c,h ld a,l ld hl,0 ;11 ld b,16 ;7 __MulFullNext: add hl,hl ;11 rla ;4 rl c ;8 jr nc,__MulFullSkip ;12/7 add hl,de ;11 adc a,0 ;7 jr nc,__MulFullSkip inc c __MulFullSkip: djnz __MulFullNext ret __MulFullEnd:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Sqrt a temp = high byte of a a <<= 8 b = 0 repeat for every 2 bits in a test = b << 8 + 0x40 b <<= 1 if (temp >= test) temp -= test set low bit of b temp += high 2 bits of a a <<= 2 return b
If a is 4 bytes, then b and temp are 2 bytes, and you loop 16 times.
Spoiler for code :
stole my own routine from axe (and modified it) p_Sqrt88: ; input in hlde, result in de ld b,16 ld a,h ld c,l push de ; ld ixh,d pop ix ; ld ixl,e ld de,0 ld h,d ld l,e __Sqrt88Loop: sub $40 sbc hl,de jr nc,__Sqrt88Skip add a,$40 adc hl,de __Sqrt88Skip: ccf rl e rl d add ix,ix rl c rla adc hl,hl add ix,ix rl c rla adc hl,hl djnz __Sqrt88Loop ret __Sqrt88End:
Logged