Skip to content

Commit a9c3c3e

Browse files
committed
Adding adding euclidean_example.asm
1 parent f75a3e0 commit a9c3c3e

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
section .text
2+
global main
3+
extern printf
4+
5+
section .data
6+
msg db "%d", 10, 0
7+
8+
euclid_mod:
9+
push ebp
10+
mov ebp, esp
11+
push esi
12+
push edi
13+
push ebx
14+
sub esp, 4
15+
mov eax, DWORD [ebp + 8]
16+
sar eax, 31
17+
xor DWORD [ebp + 8], eax
18+
sub DWORD [ebp + 8], eax
19+
mov eax, DWORD [ebp + 12]
20+
sar eax, 31
21+
xor DWORD [ebp + 12], eax
22+
sub DWORD [ebp + 12], eax
23+
jmp .while_check
24+
.while:
25+
mov eax, DWORD [ebp + 12]
26+
mov DWORD [ebp - 16], eax
27+
mov eax, DWORD [ebp + 8]
28+
cdq
29+
idiv DWORD [ebp + 12]
30+
mov DWORD [ebp + 12], edx
31+
mov eax, DWORD [ebp - 16]
32+
mov DWORD [ebp + 8], eax
33+
.while_check:
34+
cmp DWORD [ebp + 12], 0
35+
jne .while
36+
mov eax, DWORD [ebp + 8]
37+
pop ebx
38+
pop edi
39+
pop esi
40+
leave
41+
ret
42+
43+
euclid_sub:
44+
push ebp
45+
mov ebp, esp
46+
push esi
47+
push edi
48+
push ebx
49+
sub esp, 4
50+
mov eax, DWORD [ebp + 8]
51+
sar eax, 31
52+
xor DWORD [ebp + 8], eax
53+
sub DWORD [ebp + 8], eax
54+
mov eax, DWORD [ebp + 12]
55+
sar eax, 31
56+
xor DWORD [ebp + 12], eax
57+
sub DWORD [ebp + 12], eax
58+
jmp .while_check
59+
.while:
60+
mov eax, DWORD [ebp + 8]
61+
cmp eax, DWORD [ebp + 12]
62+
jle .if_true
63+
mov eax, DWORD [ebp + 12]
64+
sub DWORD [ebp + 8], eax
65+
jmp .while_check
66+
.if_true:
67+
mov eax, DWORD [ebp + 8]
68+
sub DWORD [ebp + 12], eax
69+
.while_check:
70+
mov eax, DWORD [ebp + 8]
71+
cmp eax, DWORD [ebp + 12]
72+
jne .while
73+
mov eax, DWORD [ebp + 8]
74+
pop ebx
75+
pop edi
76+
pop esi
77+
leave
78+
ret
79+
80+
main:
81+
push ebp
82+
mov ebp, esp
83+
push esi
84+
push edi
85+
push ebx
86+
push 5184
87+
push 4288
88+
call euclid_mod
89+
add esp, 8
90+
push eax
91+
push msg
92+
call printf
93+
add esp, 8
94+
push 9856
95+
push 1536
96+
call euclid_sub
97+
add esp, 8
98+
push eax
99+
push msg
100+
call printf
101+
mov eax, 0
102+
pop ebx
103+
pop edi
104+
pop esi
105+
leave
106+
ret

0 commit comments

Comments
 (0)