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

**What is a prime number?**

**Algorithm:**

**Code goes here**

1 |
<br /><br />ORG 0000h<br />LJMP MAIN<br />ORG 40h<br />MAIN: MOV R2,#11 ; Loading the number to be checked whether it's a prime or not<br />LABEL5: MOV A,R2<br /> MOV B,#02 <br /> DIV AB ;Dividing the number by 2<br /> MOV R0,A<br /> CJNE R0,#01H,LABEL2 ;Checking whether the number is 2<br /> SETB C<br /> SJMP LABEL4<br />LABEL1: DEC R0 ; decrementing and checking whether the number is not divisible by all possible values of number/2<br /> CJNE R0,#01H,LABEL2<br /> SETB C ; setting the carry flag to 1 if it is a prime number<br /> SJMP LABEL4<br />LABEL2: MOV A,R2<br /> MOV B,R0<br /> DIV AB<br /> MOV R3,B<br /> CJNE R3,#0H,LABEL1<br /> CLR C ; setting the carry falg to 0 if it not a prime number<br />LABEL4:<br /> END<br /><br /><br /> |