-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsieve.s
63 lines (46 loc) · 889 Bytes
/
sieve.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Sieve of Eratosthenes
# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
# YOUR-NAME-HERE, DD/MM/YYYY
# Constants
ARRAY_LEN = 1000
main:
li $v0, 0
li $t0, 2
outer_loop_cond:
bge $t0, ARRAY_LEN, outer_loop_end
b outer_loop_body
outer_loop_body:
lb $t3, prime($t0)
beq $t3, 0, outer_loop_increment
move $a0, $t0
li $v0, 1
syscall
li $a0, '\n'
li $v0, 11
syscall
inner_loop_init:
li $t1, 2
mul $t1, $t1, $t0
b inner_loop_cond
inner_loop_cond:
bge $t1, ARRAY_LEN, inner_loop_end
b inner_loop_body
inner_loop_body:
li $t2, 0
sb $t2, prime($t1)
b inner_loop_increment
inner_loop_increment:
add $t1, $t1, $t0
b inner_loop_cond
inner_loop_end:
b outer_loop_increment
outer_loop_increment:
addi $t0, $t0, 1
b outer_loop_cond
outer_loop_end:
b end
end:
jr $ra # return 0;
.data
prime:
.byte 1:ARRAY_LEN # uint8_t prime[ARRAY_LEN] = {1, 1, ...};