; PROGRAM: PRIME OR NOT
read macro num
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al
sub bh, 30h
mov al, 0ah
mul bh
sub bl, 30h
add al, bl
mov num, al
endm
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
msg db 'Enter Number: $'
msg_2 db 'Not defined!$'
msg_p db 'Number is Prime!$'
msg_np db 'Number is not Prime!$'
nl db 0dh,0ah,'$'
num1 db 00h
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
print msg
read num1
print nl
mov al, num1
cmp al, 00h
jz ZEROVAL
cmp al, 01h
jz NOTPRIME
mov ah, 00h
mov bh, 02h
div bh
mov cl, al
mov bl, num1
mov bh, 00h
mov dl, 02h
cmp dl, cl
jg PRIME
REDO:
mov ax, bx
div dl
cmp ah, 00h
jz NOTPRIME
cmp cl, dl
jz PRIME
inc dl
jmp REDO
ZEROVAL:
print msg_2
jmp SKIP
PRIME:
print msg_p
jmp SKIP
NOTPRIME:
print msg_np
SKIP:
mov ah, 4ch
int 21h
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>prime_or_not
Enter Number: 00
Not defined!
Z:\S5IT\masm>prime_or_not
Enter Number: 03
Number is Prime!
Z:\S5IT\masm>prime_or_not
Enter Number: 04
Number is not Prime!
Z:\S5IT\masm>prime_or_not
Enter Number: 05
Number is Prime!
**************************
0 comments:
Post a Comment