Guest User

Untitled

a guest
Jan 7th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global _start
  2.  
  3.  
  4.  
  5. section .text
  6. _start:
  7.  
  8.         mov ebx, 1
  9.         mov ecx, msgStarting
  10.         mov edx, msgStartingLen
  11.         mov eax, 4
  12.         int     0x80
  13.    
  14.         ;czyszczenie
  15.         mov     ecx, 0
  16.         mov     edx, 0
  17.         mov     ebx, 0
  18.         mov     eax, 0
  19.  
  20.  
  21.         ;pętla
  22.         mov     esi, 2D
  23.     L1:
  24.         cmp esi, 300D
  25.         jnle    next
  26.  
  27.         mov     ebx, 2
  28.         mov     edx, esi
  29.         mov ecx, edx
  30.         sub     ecx, 1      ;Odejmowanie drugiego argumentu od pierwszego. Wynik odejmowania jest umieszczany w pierwszym operandzie.
  31.         Upper:
  32.             cmp     ebx, ecx
  33.             jnl     Prime
  34.             mov     eax, edx
  35.             div     bl
  36.             cmp     ah,0
  37.             je      Increment
  38.             inc     ebx
  39.             jmp     Upper
  40.         Prime:
  41.             mov     eax, edx
  42.             call    _printDec
  43.  
  44.     Increment:
  45.     inc esi ; Increment the ESI
  46.     jmp L1
  47.  
  48.  
  49. next:
  50.     mov     ebx, 0
  51.     mov     eax, 1
  52.     int     0x80
  53.  
  54.  
  55.  
  56. _printDec:
  57. ;;; saves all the registers so that they are not changed by the function
  58.  
  59.                 section         .bss
  60. .decstr         resb            10
  61. .ct1            resd            1  ; to keep track of the size of the string
  62.  
  63.                 section .text
  64.                 pushad                          ; save all registers
  65.  
  66.                 mov             dword[.ct1],0   ; assume initially 0
  67.                 mov             edi,.decstr     ; edi points to decstring
  68.                 add             edi,9           ; moved to the last element of string
  69.                 xor             edx,edx         ; clear edx for 64-bit division
  70. .whileNotZero:
  71.                 mov             ebx,10          ; get ready to divide by 10
  72.                 div             ebx             ; divide by 10
  73.                 add             edx,'0'         ; converts to ascii char
  74.                 mov             byte[edi],dl    ; put it in sring
  75.                 dec             edi             ; mov to next char in string
  76.                 inc             dword[.ct1]     ; increment char counter
  77.                 xor             edx,edx         ; clear edx
  78.                 cmp             eax,0           ; is remainder of division 0?
  79.                 jne             .whileNotZero   ; no, keep on looping
  80.  
  81.                 inc             edi             ; conversion, finish, bring edi
  82.                 mov             ecx, edi        ; back to beg of string. make ecx
  83.                 mov             edx, [.ct1]     ; point to it, and edx gets # chars
  84.                 mov             eax, 4  ; and print!
  85.                 mov             ebx, 1
  86.                 int             0x80
  87.  
  88.         mov     ebx, 1
  89.         mov         eax, 4
  90.         mov     ecx, newLine
  91.         mov     edx, newLineLen
  92.         int         0x80
  93.  
  94.                 popad                           ; restore all registers
  95.  
  96.                 ret
  97.  
  98. section .data
  99.     msgStarting: db " Search primary number from 2 to 10 000. ",0ah
  100.     msgStartingLen: equ $-msgStarting
  101.     newLine: db "",0ah
  102.     newLineLen: equ $-newLine
Advertisement
Add Comment
Please, Sign In to add comment