readnum macro num
mov ah, 01h
int 21h
sub al, '0'
mov num, al
endm
printstring macro msg
mov ah, 09h
mov dx, offset msg
int 21h
endm
data segment
cr equ 0dh
lf equ 0ah
msg1 db cr, lf, 'enter a number: $'
msg2 db cr, lf, 'entered number is: $'
msg3 db 'PRIME $'
msg4 db 'NOT PRIME $'
msg5 db cr, lf, '$'
num db ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
printstring msg1
readnum num
printstring msg2
mov ah, 00
mov al, num
mov bh, 00
mov bl, num
dec bl
mov cl, bl
mov ch, 00
loop1:
cmp cx, 01
jle loop2
div cl
cmp ah, 00
je notprime
mov ah, 00
mov al, num
loop loop1
loop2:
printstring msg3
jmp skip
notprime:
printstring msg4
skip:
printstring msg5
mov ax, 4c00h
int 21h
code ends
end start