Q. Write an 8085 program and draw a flowchart to Find the square of an 8-bit number.(8085 Microprocessor Program)
Flowchart/Algorithm
Program
Address | Mnemonics | Operand | Opcode | Comments |
2000 | LXI | H, 3000H | 21 | Load H-L pair with address 3000H. |
2001 | 00 | |||
2002 | 30 | |||
2003 | MOV | B, M | 46 | Move the operand from memory to reg. B. |
2004 | MOV | C, M | 4E | Move the same number from reg. B to reg. C. |
2005 | MVI | A, 00H | 3E | Initialize accumulator with 00H. |
2006 | 00 | |||
2007 | ADD | B | 80 | Add B with A. |
2008 | DCR | C | 0D | Decrement reg. C (counter). |
2009 | JNZ | 2007H | C2 | Jump back to address 2007H if C ≠ 0. |
200A | 07 | |||
200B | 20 | |||
200C | INX | H | 23 | Increment H-L pair |
200D | MOV | M, A | 77 | Move the result from accumulator to memory. |
200E | HLT | 76 | Halt |
Output
Before Execution:
3000H: 03H
After Execution:
3001H: 09H
Program Explanation
- This program finds the square of an 8-bit number stored in memory location 3000H.
- The square of a number is found by multiplying it by itself.
- Therefore, the number is added to itself and is also used as a counter.
- Let us assume that the operands stored at memory location 3000H is 03H.
- Then, by using successive addition method, we get 03H + 03H + 03H = 09H.
- Initially, H-L pair is loaded with the address of the operand.
- The operand is moved to register B from memory location 3000H and then it is copied to register C.
- Accumulator is initialized to 00H.
- Register B is added to the accumulator and the result is stored in the accumulator.
- Register C (counter) is decremented by 1.
- Then, the counter is checked for zero. If it hasn’t become zero yet, then register B is again added to the accumulator, and the counter is again checked for zero.
- If counter becomes zero, then H-L pair is incremented and the result is moved from the accumulator to memory location 3001H.
An alp to find the square of number using successive addition