Thursday, February 10, 2011

Prime Test


%OUT-------------------------------------------------------------------------
%OUT- Prime & Not-Prime Test
%out- input: Enter the Number (two digit, hexadecimal)
%out- output: Prime or Composite
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------

if1
include macrolib.lby
endif

.model small
.stack
.data
i_p db "Enter No. ","$"
prm db " The Number is PRIME!!","$"
com db " The Number is COMPOSITE!!","$"

.code
main proc
showmsg i_p
input
mov ah,00h ;clear before division
mov bh,al
mov bl,02h
div bl
mov cl,al ;upper threshold to check upto
lp: mov ah,00h ;clear before each division
mov al,bh ;load the original value
div bl ;divide by next higher value
cmp ah,00h ;check if remainder zero
je comp ;composite
inc bl
cmp bl,cl ;check if threshold reached
jb lp ;not reached yet, go back, else PRIME
;its prime
showmsg prm
jmp done
;its composite
comp:
showmsg com
done:
exit
main endp
end main

No comments:

Post a Comment

Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.