-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5_04.asm
146 lines (123 loc) · 1.99 KB
/
5_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
%include "io.inc"
section .bss
digcnt resd 1
section .data
ten dd 10
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
;write your code here
GET_UDEC 4, eax
GET_UDEC 4, ecx
test eax, eax
jnz .l3
PRINT_STRING "Yes"
PRINT_CHAR 10
PRINT_UDEC 4, eax
ret
.l3:
test ecx, ecx
jz .done2
push ecx
push eax
call ROTATE
mov ebx, eax
pop eax
pop ecx
add eax, ebx
dec ecx
jmp .l3
.done2:
push eax
call ROTATE
mov ebx, eax
pop eax
cmp eax, ebx
je .YES
PRINT_STRING "No"
xor eax, eax
ret
.YES:
PRINT_STRING "Yes"
PRINT_CHAR 10
PRINT_UDEC 4, eax
xor eax, eax
ret 4
SOLVE:
push ebp
mov ebp, esp
GET_DEC 4, eax
cmp eax, 0
jnz .continue
pop ebp
ret
.continue:
push eax
call SOLVE
pop eax
PRINT_DEC 4, eax
PRINT_CHAR ' '
pop ebp
ret
POW10:
push ebp
mov ebp, esp
mov ebx, [ebp + 8]
mov eax, 1
dec ebx
.l2:
test ebx, ebx
jz .done1
mul dword[ten]
dec ebx
jmp .l2
.done1:
pop ebp
ret
ROTATE:
push ebp
mov ebp, esp
mov ebx, [ebp + 8]
push ebx
call COUNTOFDIG
pop ebx
mov ecx, eax
mov eax, ebx
xor esi, esi
.l1:
xor edx, edx
div dword[ten]
push eax
push ebx
push edx
push ecx
call POW10
mov edi, eax
pop ecx
pop edx
pop ebx
pop eax
imul edi, edx
add esi, edi
loop .l1
mov eax, esi
pop ebp
ret
COUNTOFDIG:
push ebp
mov ebp, esp
xor ebx, ebx
mov eax, [ebp + 8]
mov ecx, 10
.repeat:
xor edx, edx
cmp eax, 0
jz .done
inc ebx
div ecx
jmp .repeat
.done:
pop ebp
mov eax, ebx
ret