Friday, August 5, 2011

TASM Program Source Code to Check Whether a Number is Prime

The Program given below can be used to check whether a 2 digit number is prime or not.

  print macro msg  
  mov ah,09h  
  mov dx,offset msg  
  int 21h  
 readnum macro num  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  mov bh,0ah  
  mul bh  
  mov num,al  
  mov ah,01h  
  int 21h  
  sub al,'0'  
  add num,al  
 data segment  
  cr equ 0dh  
  lf equ 0ah  
  msg1 db 'Enter the no:','$'  
  num1 db ?  
  msg2 db cr,lf,'prime no','$'  
  msg3 db cr,lf,'not a prime no','$'  
 data ends  
 code segment  
  assume cs:code,ds:data  
  start:mov ax,data  
     mov ds,ax  
     print msg1  
     readnum num1  
     mov al,num1  
     cmp al,02h  
     je go3  
     mov ah,00h  
     mov bl,02h  
     mov bh,00h  
     mov cl,al  
     mov ah,00h  
     div bl  
     cmp ah,00h  
     je go  
     inc bx  
     mov al,num1  
     cmp bl,cl  
     jne go2  
  go3: print msg2  
     jmp exit  
  go:print msg3  
  exit:mov ah,4ch  
     mov al,00h  
     int 21h  
  code ends  
  end start  


Post a Comment


The Source Codes Published in this Blog can be used freely for Educational purposes but should not be reproduced on any other Blog or Website without the consent of the author.