Program to Find square of an 8-bit number

Q. Write an 8085 program and draw a flowchart to Find the square of an 8-bit number.(8085 Microprocessor 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


Before Execution:

3000H: 03H

After Execution:

3001H: 09H

Program Explanation

  1. This program finds the square of an 8-bit number stored in memory location 3000H.
  2. The square of a number is found by multiplying it by itself.
  3. Therefore, the number is added to itself and is also used as a counter.
  4. Let us assume that the operands stored at memory location 3000H is 03H.
  5. Then, by using successive addition method, we get 03H + 03H + 03H = 09H.
  6. Initially, H-L pair is loaded with the address of the operand.
  7. The operand is moved to register B from memory location 3000H and then it is copied to register C.
  8. Accumulator is initialized to 00H.
  9. Register B is added to the accumulator and the result is stored in the accumulator.
  10. Register C (counter) is decremented by 1.
  11. 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.
  12. If counter becomes zero, then H-L pair is incremented and the result is moved from the accumulator to memory location 3001H.

1 thought on “Program to Find square of an 8-bit number”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!