### How to check prime number using assembly language program

What is a prime number? A prime number is a natural number it has no positive divisor other than 1 and itself. Here is the microprocessor 8086 assembly language program to check whether the given number is prime or not. It is a common program for beginners who wish to study basic programming steps in assembly language.

Logic
1. suppose the given number is 'x'.
2. Let us divide the number x with (x-1). i.e. x/(x-1).
3. Now check the reminder status. Reminder is store in DX register.
4. Now divide x with x-2, i.e x/(x-2) then check the reminder.
5. Repeat this step up to the denominator become 2.
6. Denominator is like (x-1), (x-2),(x-3),....2
7. When the reminder=0, the number is 'Not Prime', else 'Prime'
Program
1. XOR CX,CX      /*Clearing the registers*/
2. XOR DX,DX      /*Clearing the registers*/
3. MOV AX,[1500]  /*Assume the number is store in memory 1500*/
4. MOV BX,AX      /*Copy the value in AX to BX */
5. DEC BX
6. DIV BX         /*Dividing*/
7. CMP DX,0000    /*Check for Reminder, Reminder is stored in DX*/
8. JZ step 13
9. XOR DX,DX      /*Clearing DX*/
10. CMP BX,0002
11. JNZ step 5
12. MOV CX,0001
13. MOV [2000],CX  /*Storing the result*/
14. HLT