-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSieve of Eratosthenes v2.asm
101 lines (88 loc) · 1.52 KB
/
Sieve of Eratosthenes v2.asm
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
; Krutik Amin
; 11/17/2015
; This programme follows sieve of Eratosthenes to
; find prime numbers upto MAX
INCLUDE Irvine32.inc
.data
MAX EQU 100
array BYTE MAX DUP(?)
comma BYTE ", ", 0
myString BYTE "Prime numbers found -", 0dh, 0ah, 0
seperator BYTE "---------------------------------------------", 0dh, 0ah, 0
.code
main proc
mov ecx, MAX
call GenerateArrayProc
;CONTINUE_LOOP:
; mov array[ecx - 1], cl
; cmp ecx, 0
; je STOP_LOOP
; loop CONTINUE_LOOP
;STOP_LOOP:
; xor edi, edi
; mov array[edi], 0
NEXT_ITERATION:
inc edi
movzx eax, array[edi]
mul eax
cmp eax, MAX
ja END_ITERATIONS
cmp array[edi], 0
jz NEXT_ITERATION
mov eax, 2
KEEP_CROSSING:
mov ebx, eax
mul array[edi]
cmp eax, MAX
ja OUT_OF_LOOP
cmp array[eax - 1], 0
jz MOVE_ON
mov array[eax - 1], 0
MOVE_ON:
mov eax, ebx
inc eax
loop KEEP_CROSSING
OUT_OF_LOOP:
loop NEXT_ITERATION
END_ITERATIONS:
mov esi, 0
xor ebx, ebx
mov edx, OFFSET myString
call WriteString
mov edx, OFFSET seperator
call WriteString
FINAL_LOOP:
cmp array[esi], 0
jz NEXT
mov al, array[esi]
call WriteDec
inc ebx
cmp ebx, 5
jle SKIP_NEWLINE
call Crlf
xor ebx, ebx
SKIP_NEWLINE:
mov edx, OFFSET comma
call WriteString
NEXT:
inc esi
cmp esi, MAX
jae EXIT_LOOP
loop FINAL_LOOP
EXIT_LOOP:
call WaitMsg
exit
main endp
;end main
GenerateArrayProc PROC
CONTINUE_LOOP:
mov array[ecx - 1], cl
cmp ecx, 0
je STOP_LOOP
loop CONTINUE_LOOP
STOP_LOOP:
xor edi, edi
mov array[edi], 0
ret
GenerateArrayProc ENDP
end main