Coding is a simple procedure for extracting the approximate root of any number.

Body #21
■········.
(c) Brom^Ellipse mdm 2383150

──────────────────────────┐   
in : HL - original number │ Not many people know what to extract
out : BC - result │ approximate root of any integer
used: HL,DE,BC,IX,A │ numbers are so simple, well, or almost
                          │ simple. The method described below was used
SQR LD BC,1 │ I think back in the early 80s. Scientifically
        LD DE,1 │ it sounds like this: Square root of
        XOR A │ of any integer is equal to the quantity
L1 OR A │ consecutive even numbers,
        SBC HL,DE │ which can be subtracted from it.
        PUSH HL │ The essence of the method is
        OR A │ to subtract all odd numbers from a number
        SBC HL,DE │ numbers (starting from 1) until result
        POP HL │ will not become zero, or until
        RET C │ the minuend will not become greater than the subtract
        INC DE │ this, the number of times subtraction and
        INC DE │ will be, rounded down, res-
        INC BC │ ltat.
        JR L1 │ On the left is the procedure for asmwhich is clearly not too
fast, but in principle everything works for me :)

Share your thoughts about the article