Sunday, September 13, 2009

Find the Square Root of a given number (8085)




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:
DIV: MVI D, 00H : Clear D-reg for Quotient
NEXT:SUB C : Subtact 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

No comments:

Post a Comment