Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/07/03 19:16
Read: times


 
#50229 - square root
Hey guys, i'm trying to do a square root function. The method I am using is subtracting odd integers from the number and counting the number of times a positive subtraction occurs before the carry bit is set. For instance, 9 = 1+3+5, so there are 3 odd integers to make 9, so the square root of 9 is 3. The problem I am having is getting it to find the square root of anything past 81. It just works for numbers that are squaes of 0-9. Also, does anyone have an algorithm for finding the square root of a number that does not have an exact whole number root(meaning square roots with decimal places)
Here is the code loop I have below, thanks.


mov r4, #00h
mov r5, #01h
mov r2, #00h
mov r3, #02h
mov counter2, #0
lcall Sub2Loop
ret

Sub2Loop: clr c

mov a, r7
subb a, r5
mov r7, a
mov a, r6
subb a, r4
mov r6, a

jc Done
inc counter2
mov a, r5
add a, r3
mov r5, a
mov a, r4
add a, r2
mov r4, a
ljmp Sub2Loop

ret

Done: mov a, counter2
acall shownum
ret

List of 9 messages in thread
TopicAuthorDate
square root            01/01/70 00:00      
   RE: square root            01/01/70 00:00      
   RE: square root            01/01/70 00:00      
   RE: square root            01/01/70 00:00      
      RE: square root            01/01/70 00:00      
         RE: square root            01/01/70 00:00      
            RE: square root            01/01/70 00:00      
               RE: square root            01/01/70 00:00      
                  RE: square root            01/01/70 00:00      

Back to Subject List