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.
- 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.
- 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),....2
- When the reminder=0, the number is 'Not Prime', else 'Prime'
- XOR CX,CX /*Clearing the registers*/
- XOR DX,DX /*Clearing the registers*/
- MOV AX, /*Assume the number is store in memory 1500*/
- MOV BX,AX /*Copy the value in AX to BX */
- DEC BX
- DIV BX /*Dividing*/
- CMP DX,0000 /*Check for Reminder, Reminder is stored in DX*/
- JZ step 13
- XOR DX,DX /*Clearing DX*/
- CMP BX,0002
- JNZ step 5
- MOV CX,0001
- MOV ,CX /*Storing the result*/