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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
| ID_x = 101
section '.data' data readable writeable
x rb 10
caption db 'Ответ',0
error db 'Ошибка ввода!!!',0
message db 'F(x)= ',0
message1 db 'F(x)=- ',0
sys dd 10
chislo dd ?
section '.code' code readable executable
start:
xor eax,eax ;ЕАХ=0
invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
or eax,eax
jz exit
lea esi, [x]
mov al, [esi]
cmp al, 2Dh
jz OTR
jnz vich
OTR: mov bl, al
INC esi
call StrToInt
not eax
add eax,1
mov ecx,eax
jmp M1
vich: call StrToInt
cmp eax, 8
ja var1 ; Если EAX>8 то переход к метке var1
jb M1
M1:
mov [chislo],3
mul [chislo] ;EAX=EAX*3
add eax,127 ; EAX=EAX+127
cmp eax, 80000000h
ja M2
jmp vivod
M2:
not eax
add eax,1
lea esi, [message1+6] ;ESI=адрес строки message+6 (для вывода результата в шаблон ответа)
call IntToStr
invoke MessageBox,HWND_DESKTOP,message1,caption,MB_OK
jmp exit
var1:
mov ebx, eax ;ebx=eax
mul eax ; eax=eax*eax
mov [chislo],3
mul [chislo] ;EAX=EAX*3
mov ecx, eax ;ecx=eax
mov eax, ebx ;eax=ebx
sub ecx, 4
mov eax, ecx
vivod:
lea esi, [message+6] ;ESI=адрес строки message+6 (для вывода результата в шаблон ответа)
call IntToStr
invoke MessageBox,HWND_DESKTOP,message,caption,MB_OK
exit:
invoke ExitProcess,0
proc IntToStr; eax - число, esi - адрес строки для вывода
pushad
mov ebx,10
xor ecx,ecx
start1:
cmp eax,0
je end1
xor edx,edx
div ebx
or dl,30h
push edx
inc ecx
jmp start1
end1:
;------ читаем из стека в буфер
start3:
cmp ecx,0
je end3
pop eax
mov [esi],al
inc esi
dec ecx
jmp start3
end3:
popad
return
endp
;********************************************************************************************
proc StrToInt ;(esi-строка):eax-число,esi-остаток строки,ecx-прочитано цифр enter
xor eax,eax
xor ecx,ecx
.l:
mul [sys]
movzx edx,byte [esi]
sub dl,30h
jc .err
cmp dl,9h
jle .next
sub dl,7h
.next:
cmp dl,byte [sys]
jnc .errs
add eax,edx
jc .err2
inc ecx
inc esi
jmp .l
.err2:
sub eax,edx
.err:
xor edx,edx
jmp .exit
.errs:
xor ecx,ecx
return
.exit:
div [sys]
return
endp
proc DialogProc,hwnddlg,msg,wparam,lparam
push ebx esi edi
cmp [msg],WM_INITDIALOG
je processed
cmp [msg],WM_COMMAND
je wmcommand
cmp [msg],WM_CLOSE
je wmclose
xor eax,eax
jmp finish
wmcommand:
cmp [wparam],BN_CLICKED shl 16 + IDCANCEL
je wmclose
cmp [wparam],BN_CLICKED shl 16 + IDOK
jne processed
invoke GetDlgItemText,[hwnddlg],ID_x,x,10
topmost_ok:
invoke EndDialog,[hwnddlg],1
jmp processed
wmclose:
invoke EndDialog,[hwnddlg],0
processed:
mov eax,1
finish:
pop edi esi ebx
return
endp
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'
import user,\
DialogBoxParam,'DialogBoxParamA',\
CheckRadioButton,'CheckRadioButton',\
GetDlgItemText,'GetDlgItemTextA',\
IsDlgButtonChecked,'IsDlgButtonChecked',\
MessageBox,'MessageBoxA',\
EndDialog,'EndDialog'
section '.rsrc' resource data readable
directory RT_DIALOG,dialogs
resource dialogs,\
37,LANG_RUSSIAN,demonstration \
dialog demonstration,'Laboratornay rabota 2',100,100,110,60,WS_CAPTION ;
dialogitem 'STATIC','X=',1,10,10,70,8,WS_VISIBLE
dialogitem 'EDIT','',ID_x,22,8,19,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP ;
dialogitem 'BUTTON','OK',IDOK,10,35,45,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON ;
dialogitem 'BUTTON','C&ancel',IDCANCEL,60,35,45,15,WS_VISIBLE+WS_TABSTOP ;
enddialog |