# 8051 code to find a square of first 10 natural numbers and store it in an array.

**8051 code to find a square of first 10 natural numbers and store it in an array.**

In this article let’s learn how to find the square of first 10 natural numbers and store them in an array.

**Algorithm:**

1)Initialize R0 with memory address where all squares are stored and R1 with 0.

2)Increment R1 to find the square of a number.

3)Find the square of a number by multiplying A and B with same number.

4)Store the result with the assigned address array.

5)Check whether R1 is 10 and if it not 10 repeat the above steps.

In this program let’s see how to find a square of first 10 natural numbers and store it in an array.

**Code goes here:**

1 |
<br />ORG 0000h<br />LJMP MAIN<br />ORG 40h<br />MAIN: MOV R0,#10H ; memory address where all the squares will be stored<br /> MOV R1,#00 <br />LOOP: INC R1 ;incrementing each time to generate a new square<br /> MOV A,R1 <br /> MOV B,R1<br /> MUL AB ;finding the square of a number<br /> MOV @R0,A ;storing the square of all the numbers in an array<br /> INC R0<br /> CJNE R1,#10,LOOP ; checking the counter value whether it has reached zero<br /> END<br /> |