forked from algorithm-archivists/algorithm-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuclidian_sub_comments.ws
38 lines (35 loc) · 1.48 KB
/
euclidian_sub_comments.ws
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
Reading the input: a, b
[SPACE][SPACE][SPACE][LF] push 0
[SPACE][SPACE][SPACE][TAB][LF] push 1
[TAB][LF][TAB][TAB] readi
[TAB][LF][TAB][TAB] readi
Loop: a, b => a, b-a
[LF][SPACE][SPACE][LF] label_0:
[SPACE][SPACE][SPACE][LF] push 0
[TAB][TAB][TAB] retrieve
[SPACE][SPACE][SPACE][TAB][LF] push 1
[TAB][TAB][TAB] retrieve
[TAB][SPACE][SPACE][TAB] sub
[SPACE][LF][SPACE] dup
[LF][TAB][SPACE][TAB][LF] jmp zero label_1
[SPACE][LF][SPACE] dup
[LF][TAB][TAB][TAB][SPACE][LF] jmp neg label_2
[SPACE][SPACE][SPACE][LF] push 0
[SPACE][LF][TAB] swap
[TAB][TAB][SPACE] store
[LF][SPACE][LF][LF] jmp label_0
Exit when a=b
[LF][SPACE][SPACE][TAB][LF] label_1:
[SPACE][SPACE][SPACE][LF] push 0
[TAB][TAB][TAB] retrieve
[TAB][LF][SPACE][TAB] printi
[LF][LF][LF] end
If a>b: a, b => a-b, b
[LF][SPACE][SPACE][TAB][SPACE][LF] label_2:
[SPACE][SPACE][SPACE][LF] push 0
[SPACE][LF][TAB] swap
[TAB][SPACE][SPACE][TAB] sub
[SPACE][SPACE][SPACE][TAB][LF] push 1
[SPACE][LF][TAB] swap
[TAB][TAB][SPACE] store
[LF][SPACE][LF][LF] jmp label_0