# Free Electronic Circuits & 8085 projects

## Find the Square Root of a given number

Published on Nov 18 2009 // Trainees

Statement: Write a program to find the Square Root of an 8 bit binary number. The binary number is stored in memory location 4200H and store the square root in 4201H.

 Source program : LDA 4200H : Get the given data(Y) in A register MOV B,A : Save the data in B register MVI C,02H : Call the divisor(02H) in C register CALL DIV : Call division subroutine to get initial value(X) in D-reg REP: MOV E,D : Save the initial value in E-reg MOV A,B : Get the dividend(Y) in A-reg MOV C,D : Get the divisor(X) in C-reg CALL DIV : Call division subroutine to get initial value(Y/X) in D-reg MOV A, D : Move Y/X in A-reg ADD E : Get the((Y/X) + X) in A-reg MVI C, 02H : Get the divisor(02H) in C-reg CALL DIV : Call division subroutine to get ((Y/X) + X)/2 in D-reg.This is XNEW MOV A, E : Get Xin A-reg CMP D : Compare X and XNEW JNZ REP : If XNEW is not equal to X, then repeat STA 4201H : Save the square root in memory HLT : Terminate program execution Subroutine Program: DIV: MVI D, 00H : Clear D-reg for Quotient NEXT:SUB C : Subtract the divisor from dividend INR D : Increment the quotient CMP C : Repeat subtraction until the JNC NEXT : divisor is less than dividend RET : Return to main program Flowchart for Program Flowchart for subroutine

Note: The square root can be taken by an iterative technique. First, an initial value is assumed. Here, the initial value of square root is taken as half the value of given number. The new value of square root is computed by using an expression XNEW = (X + Y/X)/2 where, X is the initial value of square root and Y is the given number. Then, XNEW is compared with initial value. If they are not equal then the above process is repeated until X is equal to XNEW after taking XNEW as initial value. (i.e., X XNEW)

Related Programs (Click down)