File tree Expand file tree Collapse file tree 1 file changed +92
-0
lines changed
contents/euclidean_algorithm/code/x64 Expand file tree Collapse file tree 1 file changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ .intel_syntax noprefix
2
+
3
+ . section .rodata
4
+ fmt: .string "%d\n"
5
+
6
+ . section .text
7
+ . global main
8
+ . extern printf
9
+
10
+ euclid_mod:
11
+ # Abs of the first argument
12
+ mov rax , rdi
13
+ sar rax , 31
14
+ xor rdi , rax
15
+ sub rdi , rax
16
+
17
+ # Abs of the second argument
18
+ mov rax , rsi
19
+ sar rax , 31
20
+ xor rsi , rax
21
+ sub rsi , rax
22
+
23
+ # While loop
24
+ jmp mod_check
25
+ mod_loop:
26
+ xor rdx , rdx
27
+ mov rax , rdi
28
+ div rsi
29
+ mov rdi , rsi
30
+ mov rsi , rdx
31
+ mod_check:
32
+ cmp rsi , 0
33
+ jne mod_loop
34
+
35
+ mov rax , rdi
36
+ ret
37
+
38
+ euclid_sub:
39
+ # Abs of the first argument
40
+ mov rax , rdi
41
+ sar rax , 31
42
+ xor rdi , rax
43
+ sub rdi , rax
44
+
45
+ # Abs of the second argument
46
+ mov rax , rsi
47
+ sar rax , 31
48
+ xor rsi , rax
49
+ sub rsi , rax
50
+
51
+ # While loop
52
+ jmp check
53
+ loop :
54
+ cmp rdi , rsi
55
+ jle if_true
56
+
57
+ sub rdi , rsi
58
+ jmp check
59
+ if_true:
60
+ sub rsi , rdi
61
+ check:
62
+ cmp rsi , rdi
63
+ jne loop
64
+
65
+ mov rax , rdi
66
+ ret
67
+
68
+ main:
69
+ # Calling euclid_mod
70
+ mov rdi , 4288
71
+ mov rsi , 5184
72
+ call euclid_mod
73
+
74
+ # Printing euclid_mod output
75
+ mov rdi , OFFSET fmt
76
+ mov rsi , rax
77
+ xor rax , rax
78
+ call printf
79
+
80
+ # Calling euclid_sub
81
+ mov rdi , 1536
82
+ mov rsi , 9856
83
+ call euclid_sub
84
+
85
+ # Printing euclid_sub output
86
+ mov rdi , OFFSET fmt
87
+ mov rsi , rax
88
+ xor rax , rax
89
+ call printf
90
+
91
+ xor rax , rax
92
+ ret
You can’t perform that action at this time.
0 commit comments