Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global _start
- section .text
- _start:
- mov ebx, 1
- mov ecx, msgStarting
- mov edx, msgStartingLen
- mov eax, 4
- int 0x80
- ;czyszczenie
- mov ecx, 0
- mov edx, 0
- mov ebx, 0
- mov eax, 0
- ;pętla
- mov esi, 2D
- L1:
- cmp esi, 300D
- jnle next
- mov ebx, 2
- mov edx, esi
- mov ecx, edx
- sub ecx, 1 ;Odejmowanie drugiego argumentu od pierwszego. Wynik odejmowania jest umieszczany w pierwszym operandzie.
- Upper:
- cmp ebx, ecx
- jnl Prime
- mov eax, edx
- div bl
- cmp ah,0
- je Increment
- inc ebx
- jmp Upper
- Prime:
- mov eax, edx
- call _printDec
- Increment:
- inc esi ; Increment the ESI
- jmp L1
- next:
- mov ebx, 0
- mov eax, 1
- int 0x80
- _printDec:
- ;;; saves all the registers so that they are not changed by the function
- section .bss
- .decstr resb 10
- .ct1 resd 1 ; to keep track of the size of the string
- section .text
- pushad ; save all registers
- mov dword[.ct1],0 ; assume initially 0
- mov edi,.decstr ; edi points to decstring
- add edi,9 ; moved to the last element of string
- xor edx,edx ; clear edx for 64-bit division
- .whileNotZero:
- mov ebx,10 ; get ready to divide by 10
- div ebx ; divide by 10
- add edx,'0' ; converts to ascii char
- mov byte[edi],dl ; put it in sring
- dec edi ; mov to next char in string
- inc dword[.ct1] ; increment char counter
- xor edx,edx ; clear edx
- cmp eax,0 ; is remainder of division 0?
- jne .whileNotZero ; no, keep on looping
- inc edi ; conversion, finish, bring edi
- mov ecx, edi ; back to beg of string. make ecx
- mov edx, [.ct1] ; point to it, and edx gets # chars
- mov eax, 4 ; and print!
- mov ebx, 1
- int 0x80
- mov ebx, 1
- mov eax, 4
- mov ecx, newLine
- mov edx, newLineLen
- int 0x80
- popad ; restore all registers
- ret
- section .data
- msgStarting: db " Search primary number from 2 to 10 000. ",0ah
- msgStartingLen: equ $-msgStarting
- newLine: db "",0ah
- newLineLen: equ $-newLine
Advertisement
Add Comment
Please, Sign In to add comment