Problem – Write an assembly language program in 8085 microprocessor to find square root of a number. Example –
Assumptions – Number, whose square root we need to find is stored at memory location 2050 and store the final result in memory location 3050. Algorithm –
- Assign 01 to register D and E
- Load the value, stored at memory location 2050 in accumulator A
- Subtract value stored at accumulator A from register D
- Check if accumulator holds 0, if true then jump to step 8
- Increment value of register D by 2
- Increment value of register E by 1
- Jump to step 3
- Move value stored at register E in A
- Store the value of A in memory location 3050
Program –
MEMORY ADDRESS |
MNEMONICS |
COMMENT |
2000 |
MVI D, 01 |
D <- 01 |
2002 |
MVI E, 01 |
E <- 01 |
2004 |
LDA 2050 |
A <- M[2050] |
2007 |
SUB D |
A <- A – D |
2008 |
JZ 2011 |
Jump if ZF = 0 to memory location 2011 |
200B |
INR D |
D <- D + 1 |
200C |
INR D |
D <- D + 1 |
200D |
INR E |
E <- E + 1 |
200E |
JMP 2007 |
Jump to memory location 2007 |
2011 |
MOV A, E |
A <- E |
2012 |
STA 3050 |
A -> M[3050] |
2015 |
HLT |
END |
Explanation – Registers used A, D, E:
- MVI D, 01 – initialize register D with 01
- MVI E, 01 – initialize register E with 01
- LDA 2050 – loads the content of memory location 2050 in accumulator A
- SUB D – subtract value of D from A
- JZ 2011 – make jump to memory location 2011 if zero flag is set
- INR D – increments value of register D by 1. Since it is used two times, therefore value of D is incremented by 2
- INR E – increments value of register E by 1
- JMP 2007 – make jump to memory location 2007
- MOV A, E – moves the value of register E in accumulator A
- STA 3050 – stores value of A in 3050
- HLT – stops executing the program and halts any further execution
Advantages of finding the square root:
- It is an important mathematical operation used in various fields, such as engineering, physics, and finance.
- It can be used to find the distance between two points in a coordinate plane, the length of a side of a square, or the velocity of an object.
- It is a fundamental operation used in more advanced mathematical operations, such as calculus.
Disadvantages of finding the square root:
- It can be a time-consuming and complex operation, especially for larger numbers.
- Some methods for finding the square root may not always provide an exact answer and may require rounding or approximations.
- The accuracy of the result may depend on the chosen method and the number of iterations used.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 May, 2023
Like Article
Save Article