. , , ,

,,,

,

-

:

1

:

..

_________________2007

:

-164

..

_________________2007

2007 .


:

1. . 3

2. . 3

3. .. 4

4. . 12

5. .. 14

6. ............................................ 14


a, b n. .

 

1.        

 

windowA.inc, Win32. start Win32 API, ( ). , , . , WindowProc .

, , , ,


STYLBTN equ 40000000h + 10000000h

;WSCHILD+WS_VISIBLE

STYLEDT equ 40000000h + 10000000h + 800000h + 10000h

; Win32

.486

locals

.model flat,STDCALL

include windowA.inc

includelib imp32i.lib

extrn GetModuleHandleA:PROC ;

extrn LoadIconA:PROC ;

extrn LoadCursorA:PROC ;

extrn GetStockObject:PROC ;

extrn RegisterClassExA:PROC ;

extrn CreateWindowExA:PROC ;

extrn ShowWindow:PROC ;

extrn UpdateWindow:PROC ;

extrn GetMessageA:PROC ;

extrn TranslateMessage:PROC ;

extrn DispatchMessageA:PROC ;

;

extrn ExitProcess:PROC ;

extrn BeginPaint:PROC ;

extrn EndPaint:PROC ;

extrn TextOutA:PROC ;

extrn PostQuitMessage:PROC

extrn DefWindowProcA:PROC ;

extrn MessageBoxA:PROC

extrn SendMessageA:PROC

extrn GetDC:PROC

extrn ReleaseDC:PROC

;

public WindowProc

.data

hwnd dd 0 ;

hInst dd 0 ;

hdc dd 0

;

hedt1 dd 0 ;

hbtn dd 0 ;

hh1 dd 0

hh2 dd 0

hh3 dd 0

hh4 dd 0

hbtn1 dd 0

hbtn2 dd 0

CPBUT db '&',0

CPBUT2 db '&',0

CLSBTN db 'BUTTON',0

CPEDT db '',0

CLSEDT db 'EDIT',0

TEXT db ' '

TEXTA db ' '

TEXTB db ': '

TEXTLEN = $-TEXT

ten dw 10

temp dw 0

a dd ?

b dd ?

n dd ?

wcl WNDCLASSEX <?> ;

;

message MSG <?> ;

szClassName db ' Win32',0

szTitleName db ' . -164',0

MesWindow db ' a,b n,'

MesWindowLen = $-MesWindow

ps PAINTSTRUCT <?>

.code

start proc near

;

push 0;

call GetModuleHandleA

mov hInst,eax

WinMain:

; WndClassEx

mov wcl.cbSize,type WNDCLASSEX

mov wcl.style, CS_HREDRAW+CS_VREDRAW ;

mov wcl.lpfnWndProc,offset WindowProc

mov wcl.cbClsExtra,0

mov wcl.cbWndExtra,0

mov eax,hInst

mov wcl.hInstance,eax

push IDI_APPLICATION ; 32512

push 0

call LoadIconA

mov wcl.hIcon,eax

push IDC_ARROW ; 32512

push 0

call LoadCursorA

mov wcl.hCursor,eax

;

push LTGRAY_BRUSH ;1

call GetStockObject

mov eax,5

mov wcl.hbrBackground,eax

mov dword ptr wcl.lpszMenuName,0 ;

mov dword ptr wcl.lpszClassName,offset szClassName

;

mov wcl.hIconSm,0

;

push offset wcl

call RegisterClassExA

; :

push 0 ;lpParam

push hInst ;hInstance

push 0 ;menu

push 0 ;parent hwnd

push 200 ;

push 300 ;

push 300 ; y ..

push 300 ; x ..

push WS_OVERLAPPEDWINDOW ;

push offset szTitleName ;

push offset szClassName ;

push 0 ;

call CreateWindowExA

mov hwnd,eax ;hwnd -

; :

push SW_SHOWNORMAL ;1

push hwnd

call ShowWindow

;

push hwnd

call UpdateWindow

; :

cycl_msg:

push 0

push 0

push NULL

push offset message

call GetMessageA

cmp ax,0

je end_cycl_msg

;

push offset message

call TranslateMessage

;

push offset message

call DispatchMessageA

jmp cycl_msg

end_cycl_msg:

;

push NULL

call ExitProcess

start endp

; WindowProc

WindowProc proc

arg @@hwnd:DWORD, @@mes:DWORD, @@wparam:DWORD, @@lparam:DWORD

uses ebx,edi, esi ;

local @@hdc:DWORD

cmp @@mes,WM_DESTROY

je wmdestroy

cmp @@mes,WM_CREATE

je wmcreate

cmp @@mes,WM_PAINT

je wmpaint

cmp @@mes, WM_COMMAND

je wmcommand

jmp default

wmcreate: ;

mov eax,0

;;;;1

push 0

push hInst

push 0

push @@hwnd

push 20

push 35

push 50

push 10

push STYLEDT

push offset CPEDT

push offset CLSEDT

push 0

call CreateWindowExA

mov hh1,eax

mov eax,0

;;; 2

push 0

push hInst

push 0

push @@hwnd

push 20

push 35

push 50

push 50

push STYLEDT

push offset CPEDT

push offset CLSEDT

push 0

call CreateWindowExA

mov hh2,eax

mov eax,0

;;;;;;3

push 0

push hInst

push 0

push @@hwnd

push 20

push 35

push 50

push 90

push STYLEDT

push offset CPEDT

push offset CLSEDT

push 0

call CreateWindowExA

mov hh3,eax

mov eax,0

;;;;;

push 0

push hInst

push 0

push @@hwnd

push 20

push 80

push 80

push 10

push STYLBTN ;STYLBTN

push offset CPBUT

push offset CLSBTN

push 0

call CreateWindowExA

mov hbtn,eax

mov eax,0

push 0

push hInst

push 0

push @@hwnd

push 20

push 80

push 80

push 100

push STYLBTN ;STYLBTN

push offset CPBUT2

push offset CLSBTN

push 0

call CreateWindowExA

mov hbtn2,eax

mov eax,0

; 0

jmp exit_wndproc

wmcommand:

mov eax, hbtn

cmp @@lparam,eax

je calc

mov eax, hbtn2

cmp @@lparam,eax

je res

wmnodestroy:

mov eax,0

jmp exit_wndproc

res:

jmp wmdestroy

wmpaint:

push offset ps

push @@hwnd

call BeginPaint

mov @@hdc,eax

push MesWindowLen

push offset MesWindow

push 20

push 10

push @@hdc

call TextOutA

;

push offset ps

push @@hdc

call EndPaint

mov eax,0 ; 0

jmp exit_wndproc

wmdestroy: ; WM_QUIT

push 0

call PostQuitMessage

mov eax,0 ; 0

jmp exit_wndproc

default:

;

push @@lparam

push @@wparam

push @@mes

push @@hwnd

call DefWindowProcA

jmp exit_wndproc

calc:

; 1

push offset TEXTA

push 150

push WM_GETTEXT

push hh1

call SendMessageA

push offset TEXTA

call StringToDig

mov a,eax

; 2

push offset TEXTA

push 150

push WM_GETTEXT

push hh2

call SendMessageA

push offset TEXTA

call StringToDig

mov b,eax

; 3

push offset TEXTA

push 150

push WM_GETTEXT

push hh3

call SendMessageA

push offset TEXTA

call StringToDig

mov n,eax

mov ecx,n

mov eax,1d

repeat:

imul a

loop repeat

imul b

aam

or ax,3030h

mov [TEXTB+12],ah

mov [TEXTB+13],al

push @@hwnd

call GetDC

mov @@hdc,eax

push 18

push offset TEXTB

push 120

push 10

push @@hdc

call TextOutA

exit_wndproc:

ret

WindowProc endp

StringToDig proc near

ARG @@TEXT:DWORD

mov esi,@@TEXT

mov eax,0

mov edx,0

mov dl,[esi]

cmp dl,'-'

jne N

mov temp,1

inc esi

mov dl,[esi]

N: cmp dl,'0'

jl MRET

cmp dl,'9'

jg MRET

and dl,0Fh ; ASCII->BCD

add eax,edx

mul ten

inc esi

mov dl,[esi]

cmp dl,'0'

jl MDIV

cmp dl,'9'

jg MDIV

; mul ten

and dl,0Fh

add eax,edx

jmp MRET

MDIV: div ten

MRET:

cmp temp,1

jne n1

imul eax,-1

mov temp,0

n1: ret

StringToDig endp

end start


2.        


3.        

1)

2)

3)

4)

, , , .

- :

 

 

 

! , , , .
. , :