Skip to content

Instantly share code, notes, and snippets.

@sivaramaaa
Last active May 25, 2016 09:29
Show Gist options
  • Save sivaramaaa/8d269e4d91fa16f87b14046832989fa7 to your computer and use it in GitHub Desktop.
Save sivaramaaa/8d269e4d91fa16f87b14046832989fa7 to your computer and use it in GitHub Desktop.
Check_prime
extern printf
extern scanf
section .data
fmts: db "%d",0
prompt: db "Enter the number ",10,0
msg2: db "It is prime ",10,0
msg3: db "It is not a prime ",10,0
num1: dd 0
num2: dd 2
section .text
global main
main:
push ebp
mov ebp,esp
push prompt
call printf
add esp,4
push num1
push fmts
call scanf
add esp,8
cmp DWORD[num1],1
je notprime
cmp DWORD[num1],2
je primep
mov ebx,2
mov eax,DWORD[num1]
mov ecx, DWORD[num2]
mov edx,0
div ecx
prime:
mov eax,DWORD [num1]
mov edx,0
div ebx
cmp edx,0
je notprime
inc ebx
push eax
cmp ebx,ecx
jl prime
push msg2
call printf
add esp,4
jmp exit
mov eax,0
notprime:
push msg3
call printf
add esp,4
jmp exit
primep:
push msg2
call printf
add esp,4
exit:
mov eax,0
mov esp,ebp
pop ebp
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment