Skip to content

Instantly share code, notes, and snippets.

@DeRegem
Created November 3, 2015 01:33
Show Gist options
  • Save DeRegem/2ef039900f9face9992a to your computer and use it in GitHub Desktop.
Save DeRegem/2ef039900f9face9992a to your computer and use it in GitHub Desktop.
format PE
entry main
section '.text' code readable executable
main:
;EBX=Divisor que va a ir de n-1 hasta 2
mov ebx,17
;Alojo en ECX el resultado, presumo numero primo
mov ecx,1
_bucle:
;En EDX queda el resto de DIV, seteo en 0
xor edx,edx
;si llega a 2, es primo, termino ciclo
cmp ebx,2
jle _final
;EAX=N
mov eax,17
dec ebx
div ebx
and edx,edx
;Si no es 0, sigue siendo primo, vuelvo al ciclo
jnz _bucle
;Entra si es primo, alojo resultado en ECX
mov ecx,0
_final:
mov eax,ecx
push eax
push format_output2
call [printf]
add esp, 8
push num
push format_input
call [scanf]
add esp, 8
push 0
call [exit]
ret
section '.data' data readable writeable
num db ?
format_input db "%d",10,0
format_output db "%s",10,0
format_output2 db "%d",10,0
section '.idata' data import readable
include "macro\import32.inc"
library msvcrt, "MSVCRT.DLL"
import msvcrt,\
printf ,'printf',\
scanf ,'scanf',\
exit ,'exit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment