Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to check whether the number inputted is prime or not

Posted By: Sarah Campbell     Category: Assembly Language     Views: 40635

A Program to check whether the number inputted is prime or not.

Code for Program to check whether the number inputted is prime or not in Assembly Language

.MODEL  SMALL
    .DATA
           VAl1     DB      ?
           NL1      DB      0AH,0DH,'ENTER NO:','$'
           NL2      DB      0AH,0DH,'IT IS NOT PRIME','$'
           NL3      DB      0AH,0DH,'IT IS PRIME','$'

           .CODE
    MAIN    PROC

            MOV AX,@DATA
            MOV DS,AX

            LEA DX,NL1
            MOV AH,09H
            INT 21H
    
            MOV AH,01H
            INT 21H
            SUB AL,30H
            MOV VAL1,AL
            
           MOV AH,00

            MOV CL,2
            DIV CL
            MOV CL,AL

    LBL1:
            MOV AH,00
            MOV AL,VAL1
            DIV CL
            CMP AH,00
            JZ LBL2
            DEC CL
            CMP CL,1
            JNE LBL1
            JMP LBL3
    
    LBL2:
    
            MOV AH,09H
            LEA DX,NL2
            INT 21H
            JMP EXIT    
    
    LBL3:
            MOV AH,09H
            LEA DX,NL3
            INT 21H
    
    EXIT:
            MOV AH,4CH
            INT 21H
    
    MAIN    ENDP
            END     MAIN
    

 OUTPUT
************
 Z:\assembly\SYSTEM~1\AS2>ex05

ENTER NO:4
IT IS NOT PRIME
Z:\assembly\SYSTEM~1\AS2>ex05

ENTER NO:5
IT IS PRIME       
  
Share: 



Sarah Campbell
Sarah Campbell author of Program to check whether the number inputted is prime or not is from Toronto, Canada.
 
View All Articles

 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Amay Mao from United States Comment on: Mar 20
how can I write an 8051 assembly language program that determines if a number is prime or not.

I have to do :
o Input value is stored in R0 (you can just type it in from within the simulator or do a mov
command
o Output value is a 1 stored in R0 if the input value was prime, a 0 stored in R0 if the input
value was not prime
o Provide comments in the source file that describe how you tested your program for
correct operation and describe the results of those tests
o Turn in printed source code

Rifat Hasan from Bangladesh Comment on: Dec 08
very very nice &logical

View All Comments