Guest User

Untitled

a guest
Nov 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. ;NUM is assigned to the Number to be checked
  2. ;AL is used as the default no
  3. ;BL is used as Dividing Variable. It is Incremented in each loop
  4. ;BH is used to know the number of variables which can divide the Number. BH>02, The number is not prime
  5. ;BL is made to run x number of times, where x is the given number.
  6.  
  7. ; Declaration Part
  8. .MODEL SMALL
  9. .DATA
  10. MSG DB "The Give No is a Prime No$"
  11. NMSG DB "The Given No is not a Prime No$"
  12. NUM DB 71H ;Enter the required no here
  13. .CODE
  14.  
  15. START: MOV AX,@DATA
  16. MOV DS,AX
  17.  
  18. MOV AL,NUM
  19. MOV BL,02H ; The Dividing starts from 2, Hence BH is compare to 02H
  20. MOV DX,0000H ; To avoid Divide overflow error
  21. MOV AH,00H ; To avoid Divide overflow error
  22.  
  23. ;Loop to check for Prime No
  24. L1:DIV BL
  25. CMP AH,00H ; Remainder is compared with 00H (AH)
  26. JNE NEXT
  27. INC BH ; BH is incremented if the Number is divisible by current value of BL
  28. NEXT:CMP BH,02H ; If BH > 02H, There is no need to proceed, It is not a Prime
  29. JE FALSE ; The no is not a Prime No
  30. INC BL ; Increment BL
  31. MOV AX,0000H ; To avoid Divide overflow error
  32. MOV DX,0000H ; To avoid Divide overflow error
  33. MOV AL,NUM ; Move the Default no to AL
  34. CMP BL,NUM ; Run the loop until BL matches Number. I.e, Run loop x no of times, where x is the Number given
  35. JNE L1 ; Jump to check again with incremented value of BL
  36.  
  37. ;To display The given no is a Prime No
  38. TRUE: LEA DX,MSG
  39. MOV AH,09H ; Used to print a string
  40. INT 21H
  41. JMP EXIT
  42.  
  43. ;To display The given no is not a Prime No
  44. FALSE: LEA DX,NMSG
  45. MOV AH,09H ; Used to print a string
  46. INT 21H
  47.  
  48.  
  49. EXIT:
  50. MOV AH,4CH
  51. INT 21H
  52. END START
Add Comment
Please, Sign In to add comment