-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_04.asm
103 lines (97 loc) · 1.58 KB
/
10_04.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
102
103
%include "io.inc"
section .bss
k resd 1
ans resd 1
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
;write your code here
GET_UDEC 4, ecx
GET_UDEC 4, ebx
GET_UDEC 4, eax
dec ecx
.l1:
test ecx, ecx
jz .done
GET_UDEC 4, edi
GET_UDEC 4, edx
push ecx
push ebx
push eax
push edi
push edx
call SUM
add esp, 16
pop ecx
dec ecx
jmp .l1
.done:
PRINT_UDEC 4, ebx
PRINT_CHAR ' '
PRINT_UDEC 4, eax
xor eax, eax
ret
SUM:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ebx, [ebp+16]
push eax
push ebx
call GCD
mov ecx, eax
pop ebx
pop eax
mul ebx
div ecx
push eax
xor esi, esi
xor edx, edx
div dword[ebp+16]
mul dword[ebp+20]
add esi, eax
pop eax
push eax
xor edx, edx
div dword[ebp+8]
mul dword[ebp+12]
add esi, eax
pop eax
.exit:
mov ebx, esi
push ebx
push eax
call GCD
mov ecx, eax
pop ebx
pop eax
xor edx, edx
div ecx
push eax
mov eax, ebx
xor edx, edx
div ecx
mov ebx, eax
pop eax
xchg eax, ebx
pop ebp
ret
GCD:
push ebp
mov ebp, esp
mov ebx, [ebp + 8]
mov eax, [ebp + 12]
cmp ebx, 0
jnz .continue
pop ebp
ret
.continue:
push ebx
xor edx, edx
div ebx
push edx
call GCD
add esp, 8
pop ebp
ret