Monday, February 14, 2011

Check wheather the given number is prime or not

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm read macro n,j1,j2 j1:mov ah,01h int 21h cmp al,0dh je j2 sub al,30h mov bl,al mov ax,n mov dx,0ah mul dx xor bh,bh add ax,bx mov n,ax jmp j1 j2 :nop endm .model small .stack 100h .data msg1 db 10,13,'Enter the number: $' msg2 db 10,13,'Prime Number $' msg3 db 10,13,'Not a Prime Number$' msg4 db 10,13,'Invalid Entry$' num dw 0 .code main proc mov ax,@data mov ds,ax print msg1 ;reading 1st multidigit number read num,jump1,jump2 mov ax,num ;if num=0 cmp ax,00 jne notzero print msg4 jmp stop notzero:;if num=1 or 2 cmp ax,03 jnc jump3 jmp prim ;check wheather num is prime or not jump3:mov cx,02 div cx mov cx,ax mov bx,02 loop1:xor dx,dx mov ax,num div bx cmp dx,00 je notprim inc bx loop loop1 prim:print msg2 jmp stop notprim:print msg3 stop:mov ah,4ch int 21h main endp end

No comments:

Post a Comment