8051 code to find number of prime numbers in array stored in memory with starting address 0xA0

8051 code to find number of prime numbers in array stored in memory with starting address 0xA0

 

What is a prime number?

Prime number is a number which divides by 1 and itself.So when we are taking in the program we have to take and check for the numbers which are not divisible by the half of the number to be checked as a prime number.
eg: If we are checking for 11 as a prime number then it should not be divisible by numbers from 2 to 5(11/2).

Algorithm:

1)Store the memory address of the array in R1 where all the numbers should be checked and in R0 where all the checked prime numbers are stored.
2)Divide the number by 2 and store it in the register R3.
3)Check whether the R3 is 1 if it is one then it is a primenumber.
4)If R3 is not 1 then go on dividing the prime number with all the numbers till R3 is 1(By decrementing R0 by 1).
5)If R3 is one then the number is a prime number as it is not divisible by any number except one and       itself.
6)Then store the number in an array where all the prime numbers are stored.
7)Suppose if the remainder dividing A(to be checked as a prime number) by any number is zero then    break the loop and check the next number in an array.
Let’s learn how to code to check the number stored in an array is a prime or not and store all the prime numbers in a different array.

Code goes here:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Advertisment ad adsense adlogger