assembly - Finding the square root of a number -
i want know how find square root in easy68k assembler.
i know it's function don't know code it.
i want find square root of 72.
the answer should integer 8 in case.
i found algorithm:
value-->c1 loop: value/c1-->c2 (c1+c2)/2-->c1 until c1=c2 c1-->result i converted 68k code:
move.w #72,d2 ; value = 64 move.l d2,d5 ; c1 = 64 move.l d5,d3 ; hold d3 = 64 loop divs d2,d3 ; value/c1 move.l d3,d6 ; move answer above c2 = d6 add.l d5,d6 ; add c1+c2 divs #2,d6 move.l d6,d5 ; move answer above d4 = c1 cmp.l d6,d5 beq loop move.l d5,d7 ; d7 have result and doesn't work reason.
the division @ beginning of loop not divide value c1 except on first iteration. since value in d2 , c1 in d5 should replace:
divs d2,d3 ; value/c1 move.l d3,d6 ; move answer above c2 = d6 with:
move.l d2,d1 ; temp = value divs d5,d1 ; temp /= c1 move.l d1,d6 ; d6 = value / c1 i found unclear whether you're using divs.w or divs.l. if you're using divs.w you'll have keep in mind d1 contain both quotient , remainder after division.
Comments
Post a Comment