# 8085 program to determine if the number is prime or not

In this program we will see how to check a number is prime or not using 8085.

## Problem Statement

Write 8085 Assembly language program to check whether a given number is prime or not.

## Discussion

Here the approach is little bit different. We are actually counting the number of unique factors. For prime numbers the factors are only two. The 1 and the number itself. So if the result is 02H, then it is prime, otherwise not a prime number. As there is no division operation, we have to perform division by subtracting repeatedly.

Data
F100
07

Data
F100
FF

Data
F100
2F

## Program

HEX Codes
Labels
Mnemonics
F000
21, 00, F1

LXI H,F100
Point to F100 to take the number
F003
FE

MOV A,M
Take the number into Accumulator
F004
0E

MVI C,00
Clear C register
F006
57

MOV D,A
Copy A to D
F007
5F

MOV E,A
Copy A to E
F008
42
L2
MOV B,D
F009
B8
L1
CMP B
Compare B with A
F00A
DA, 11, F0

JC LABEL
F00D
90

SUB B
Subtract B from A
F00E
C2, 09, F0

JNZ L1
F011
FE, 00
LABEL
CPI 00
Compare A with 00H
F013
C2, 17, F0

JNZ SKIP
F016
0C

INR C
Increase C by 1
F017
7B
SKIP
MOV A,E
F018
15

DCR D
Decrease D by 1
F019
C2, 08, F0

JNZ L2
F01C
79

MOV A,C
F01D
32, 01, F1

STA F101
Store result into F101
F020
76

HLT
Terminate the program

## Output

Data
F150
02

This is Prime

Data
F150
08

This is not prime

Data
F150
02

This is Prime