Assembly language program for checking number is prime or not

Program:

LDA 2029 ;A=5
MVI C,00               ;STORE NO OF DIVISOR OF N
MOV E,A                ; iterator for the loop from n to 1.
LOOP1: MOV B,A ; B permanently stores n
LOOP2: MOV D,E ; D as the divisor
CMP D
JC DLN
SUB D   ;Division: Keep subtracting D from A
               ;till the value in A either becomes 0
               ; or less than 0
JNZ LOOP2
DLN: CPI 0
JNZ NT
INR C
NT: MOV A,B
DCR E
JNZ LOOP1
MOV A,C
MVI C,00
CPI 02
JNZ COMPOSITE
INR C
COMPOSITE: MOV A,C
STA 2030
Result:
           Case1-

Memory Location
Data value
2029
5
2030
1 is  Prime
              

              Case2-

Memory Location
Data value
2029
12
2030
0   is Not Prime
 

Comments

Popular posts from this blog

Preamble to the Constitution of India:

Designing a calculator using HTML and JavaScript