**What is a Prime number**?

A prime number is a natural number it has

**no positive divisor**other than

**1**and

**itself**.Prime number checking program is a beginner program for any programming language. In

**8086 assembly**language, checking prime number is an interesting logic.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 for 8086 microprocessor.

** Read Also:** Stepper Motor Interfacing with 8086

## Logic of Prime Number Check in Assembly Code

- Before going to the assembly code let me explain the programming logic first.

- Suppose the given number is ‘x’. Let us divide the number x with (x-1). I.e. x/(x-1).

- Now check the reminder status. Reminder is store in DX register b default.

- Now divide x with x-2, i.e. x/(x-2) then check the reminder.

- Repeat this step up to the denominator become 2.

- Denominator is like (x-1), (x-2),(x-3),….etc. 2

- When the reminder=0, the number is ‘Not Prime’, else it is ‘Prime’

## Prime Number Program in 8086

Now let’s see the 8086 assembly language code for prime number checking.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 1000 XOR CX,CX /*Clearing the registers*/ 1002 XOR DX,DX /*Clearing the registers*/ 1004 MOV AX,[1500] /*Assume the number is store in memory 1500*/ 1006 MOV BX,AX /*Copy the value in AX to BX */ 1008 DEC BX 1010 DIV BX /*Dividing*/ 1012 CMP DX,0000 /*Check for Reminder, Reminder is stored in DX*/ 1014 JZ step 13 1016 XOR DX,DX /*Clearing DX*/ 1018 CMP BX,0002 1020 JNZ 1008 1022 MOV CX,0001 1024 MOV [2000],CX /*Storing the result*/ 1026 HLT |

If you have any doubts regarding to the above described assembly language program feel free to ask using the comment box below. Keep visiting ** CircuitsGallery** for more about 8086.

*You may also like:*
The above programe which u hav published above for finding whether the number is prime or not is not right and it has a wrong logic

plzz correct it