-
Notifications
You must be signed in to change notification settings - Fork 0
/
061.asm
141 lines (123 loc) · 2.94 KB
/
061.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
section .data
msg db "%d", 10, 0 ;return string for printf (just the result)
section .bss
nums resb 10000 ;for bit flags
first resb 10000 ;for first two digits
last resb 10000 ;for last two digits
nset resd 6 ;for sets
section .text
extern printf
global main
main:
mov edi, 1
xor eax, eax
xor ebx, ebx
;set flags for all figurate numbers
set_tri:
mov bl, [nums + eax]
bts ebx, 0
mov [nums + eax], bl
add eax, edi
inc edi
cmp eax, 10000
jl set_tri
mov edi, 1
xor eax, eax
set_squ:
mov bl, [nums + eax]
bts ebx, 1
mov [nums + eax], bl
add eax, edi
add edi, 2
cmp eax, 10000
jl set_squ
mov edi, 1
xor eax, eax
set_pen:
mov bl, [nums + eax]
bts ebx, 2
mov [nums + eax], bl
add eax, edi
add edi, 3
cmp eax, 10000
jl set_pen
mov edi, 1
xor eax, eax
set_hex:
mov bl, [nums + eax]
bts ebx, 3
mov [nums + eax], bl
add eax, edi
add edi, 4
cmp eax, 10000
jl set_hex
mov edi, 1
xor eax, eax
set_hep:
mov bl, [nums + eax]
bts ebx, 4
mov [nums + eax], bl
add eax, edi
add edi, 5
cmp eax, 10000
jl set_hep
mov edi, 1
xor eax, eax
set_oct:
mov bl, [nums + eax]
bts ebx, 5
mov [nums + eax], bl
add eax, edi
add edi, 6
cmp eax, 10000
jl set_oct
mov edi, 1000
mov ebx, 100
get_first_last: ;get first/last two digits
mov eax, edi
xor edx, edx
div ebx
mov [first + edi], al
mov [last + edi], dl
inc edi
cmp edi, 10000
jl get_first_last
xor eax, eax ;result
xor ebx, ebx ;for flags
xor ecx, ecx ;dito
mov edi, 999 ;init n
next_starter:
inc edi
mov bl, [nums + edi]
test ebx, ebx
jz next_starter
push rdi ;remember starter
mov [nset], edi
mov r9b, [last + edi]
mov esi, 1 ;index for nset
mov edi, 999
next_follower:
inc edi
cmp edi, 10000
je backtrack
mov cl, [nums + edi]
or ecx, ebx
cmp ecx, ebx
je next_follower
cmp r9b, [first + edi]
jne next_follower
backtrack:
mov byte [nest + esi], 0
dec esi
mov eax, edi
print:
push rbp
mov edi, msg
mov esi, eax
call printf
pop rbp
exit:
mov eax, 1
xor edi, edi
syscall
section .note.GNU-stack ;just for gcc