Skip to content

Instantly share code, notes, and snippets.

@matthiasdebernardini
Created November 27, 2017 09:07
Show Gist options
  • Save matthiasdebernardini/01449e829896e536fb6a55356ef172c6 to your computer and use it in GitHub Desktop.
Save matthiasdebernardini/01449e829896e536fb6a55356ef172c6 to your computer and use it in GitHub Desktop.
Eratosthenes Sieve
1 .bss
2 NUMBERS: .skip 1000
3
4 .text
5 formatstr: .asciz "%d\n"
6
7 .global main
8
9 main:
10 movq %rsp, %rbp
11 movq $0, %rbx
12
13 loop1:
14 movb $1, NUMBERS(%rbx)
15 incq %rbx
16 cmpq $1000, %rbx
17 jl loop1
18 pushq $2
19
20 loop2:
21 movq -8(%rbp), %rbx
22 cmpq $1, NUMBERS(%rbx)
23 jne lp2end
24 movq $formatstr, %rdi
25 movq %rbx, %rsi
26 movq $0, %rax
27 call printf
28 movq -8(%rbp), %rbx
29 shlq $1, %rbx
30
31 loop3:
32 cmpq $1000, %rbx
33 jge lp2end
34 movb $0, NUMBERS(%rbx)
35 addq -8(%rbp), %rbx
36 jmp loop3
37
38 lp2end:
39 movq -8(%rbp), %rbx
40 incq %rbx
41 movq %rbx, -8(%rbp)
42 cmpq $1000, %rbx
43 jl loop2
44
45 end:
46 mov $0, %rdi
47 call exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment