Uncategorized

8051 code to check whether the number is prime or not…!!

8051 Program to check whether the given number is prime or not.

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 number to be checked as a prime number in the register R2.
2)Divide the number by 2 and store it in the register R0.
3)Check whether the R0 is 1 if it is one then it is a primenumber.
4)If R0 is not 1 then go on dividing the prime number with all the numbers till R0 is 1(By decrementing R0 by 1).
5)Then check if R0 is 1.If it is 1 then set the carry flag to 1 indicating that it is a prime number.
6)Suppose if the remainder dividing R2 by any number is zero then set the carry falg to 0 indicating it is not a prime number.
In this program let’s learn how to check whether the number is prime or not…….!!!

Code goes here