Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "asm_io.inc"
  2.  
  3. CPU 386
  4.  
  5. segment .data
  6.   msg        db   "Trova i numeri primi da 2 ad N. Inserisci N: ",0
  7.  
  8. segment .bss
  9.   n     resq   1
  10.   temp  resq   1
  11.  
  12. segment .text
  13.   global _asm_main
  14.  
  15. _asm_main:
  16.   enter 0,0
  17.   pusha
  18.  
  19.   mov   eax,msg
  20.   call  print_string
  21.   call  read_int
  22.   mov   [n],eax
  23.   jmp   test_primalita
  24. test_primalita:
  25.   mov   eax,2
  26.   call  print_int
  27.   call  print_nl
  28.   mov   eax,3
  29. while_primo:
  30.   cmp   eax,[n]
  31.   jnle  end_primo
  32.   mov   ebx,3
  33. while_secondo:
  34.   cmp   ebx,eax
  35.   jnl   end_secondo
  36.   mov   [temp],ebx
  37.   mov   ecx,eax
  38.   mov   edx,0
  39.   idiv  ebx
  40.   cmp   edx,0
  41.   mov   eax,ecx
  42.   je    end_secondo
  43.   mov   ebx,[temp]
  44.   add   ebx,2
  45.   jmp   while_secondo
  46. end_secondo:
  47.   cmp   edx,0
  48.   jne   stampa
  49.   jmp   continua
  50. stampa:
  51.   call  print_int
  52.   call  print_nl
  53.   jmp   continua
  54. continua:
  55.   add   eax,2
  56.   jmp   while_primo
  57. end_primo:
  58.   popa
  59.   mov   eax,0
  60.   leave
  61.   ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement