Skip to content

Instantly share code, notes, and snippets.

@mrafayaleem
Created August 30, 2012 11:35
Show Gist options
  • Save mrafayaleem/3526790 to your computer and use it in GitHub Desktop.
Save mrafayaleem/3526790 to your computer and use it in GitHub Desktop.
Include Irvine32.inc
.data
myA DWORD ?
myI DWORD ?
prompt1 BYTE "ENTER THE NUMBER TO BE TESTED:", 0
prompt2 BYTE "NOT PRIME", 0
prompt3 BYTE "YES PRIME", 0
prompt4 BYTE "INVALID INPUT", 0
.code
main PROC
OUTERLOOP:
call input
mov myI, 2
mov eax, myA
cmp eax, 2
JL INVALID
JE YESPRIME
MYLOOP:
mov eax, myA
cdq
idiv myI
cmp edx, 0
je NOTPRIME
inc myI
mov eax, myI
cmp eax, myA
jae YESPRIME
JMP MYLOOP
NOTPRIME:
mov edx, OFFSET prompt2
call WriteString
call crlf
JMP FINISH
YESPRIME:
mov edx, OFFSET prompt3
call WriteString
call crlf
JMP FINISH
INVALID:
mov edx, OFFSET prompt4
call WriteString
call crlf
FINISH:
JMP OUTERLOOP
exit
main ENDP
input PROC uses eax edx
mov edx, OFFSET prompt1
call WriteString
call crlf
call ReadInt
mov myA, eax
ret
input ENDP
END main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment