-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssembly1.asm
More file actions
1035 lines (842 loc) · 36.4 KB
/
Assembly1.asm
File metadata and controls
1035 lines (842 loc) · 36.4 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; *************************************************************************
; 32-bit Windows Standard Application
; Nobita4x4m
; *************************************************************************
.686 ; Enable 80686+ instruction set
.model flat, stdcall ; Flat, 32-bit memory model (not used in 64-bit)
option casemap: none ; Case sensitive syntax
; *************************************************************************
; MASM32 proto types for Win32 functions and structures
; *************************************************************************
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
include F:\masm32\include\windows.inc
include F:\masm32\include\user32.inc
include F:\masm32\include\kernel32.inc
include F:\masm32\include\masm32.inc
; *************************************************************************
; MASM32 object libraries
; *************************************************************************
includelib F:\masm32\lib\user32.lib
includelib F:\masm32\lib\kernel32.lib
includelib F:\masm32\lib\msvcrt.lib
; *************************************************************************
; Our data section.
; *************************************************************************
.data
ClassName db "SimpleWinClass", 0
AppName db "Simple Caculator", 0
MenuName db "First Menu", 0
ButtonClassName db "Button", 0
ClearButtonClassName db "Button", 0
EditClassName db "Edit", 0
Button0 db "0", 0
Button1 db "1", 0
Button2 db "2", 0
Button3 db "3", 0
Button4 db "4", 0
Button5 db "5", 0
Button6 db "6", 0
Button7 db "7", 0
Button8 db "8", 0
Button9 db "9", 0
ButtonPlus db "+", 0
ButtonMinus db "-", 0
ButtonMultiply db "X", 0
ButtonDivide db "/", 0
ButtonClear db "AC", 0
ButtonEqual db "=", 0
; *************************************************************************
; Our data unitialised section
; *************************************************************************
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ?
hwndClear HWND ?
hwndEdit HWND ?
buffer db 512 dup(?)
Para1 db 20 dup(?)
Para2 db 20 dup(?)
idx db 20 dup(0)
K db 20 dup(0)
Caculate db 20 dup(0)
result db 512 dup(?)
; *************************************************************************
; Constants.
; *************************************************************************
.Const
EditID equ 21
ButtonZeroID equ 0
ButtonOneID equ 1
ButtonTwoID equ 2
ButtonThreeID equ 3
ButtonFourID equ 4
ButtonFiveID equ 5
ButtonSixID equ 6
ButtonSevenID equ 7
ButtonEightID equ 8
ButtonNineID equ 9
ButtonPlusID equ 10
ButtonMinusID equ 11
ButtonMultiplyID equ 12
ButtonDivideID equ 13
ButtonClearID equ 14
ButtonEqualID equ 15
IDM_ZERO equ 0
IDM_ONE equ 1
IDM_TWO equ 2
IDM_THREE equ 3
IDM_FOUR equ 4
IDM_FIVE equ 5
IDM_SIX equ 6
IDM_SEVEN equ 7
IDM_EIGHT equ 8
IDM_NINE equ 9
IDM_PLUS equ 10
IDM_MINUS equ 11
IDM_MULTIPLY equ 12
IDM_DIVIDE equ 13
IDM_CLEAR equ 14
IDM_EQUAL equ 15
; *************************************************************************
; Marcos.
; *************************************************************************
; *************************************************************************
; Our executable assembly code starts here in the .code section
; *************************************************************************
.code
start:
;xor esi, esi
xor edi, edi
push NULL
call GetModuleHandle
mov hInstance, eax
call GetCommandLine
mov CommandLine, eax
push SW_SHOWDEFAULT
push CommandLine
push NULL
push hInstance
call WinMain
; Exit APP
push 0
call ExitProcess
;The Main fuction for the app
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
; LOCAL wc:WNDCLASSEX tells MASM to allocate memory from the stack the size of WNDCLASSEX structure for the variable named wc.
Local wc:WNDCLASSEX ; 4 - An instance of the window class
Local msg:MSG ; A message from and to the window
Local hwnd:HWND ; The handle to the window
Mov wc.cbSize,SIZEOF WNDCLASSEX ; The size of this instance of the window struct
Mov wc.style, CS_HREDRAW or CS_VREDRAW ; The style of the window
Mov wc.lpfnWndProc, Offset WndProc ; The point to the window procedure
Mov wc.cbClsExtra, NULL ; The number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero.
Mov wc.cbWndExtra, NULL ; The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero
Push hInst ; Push the instance that contains the window procedure for the class onto the stack
Pop wc.hInstance ; A handle to the instance that contains the window procedure for the class.
Mov wc.hbrBackground, COLOR_BTNFACE + 1 ; A handle to the class background brush.
; A color value must be one of the standard system colors (the value 1 must be added to the chosen color)
Mov wc.lpszMenuName, Offset MenuName ; Pointer to a null-terminated character string that specifies the resource name of the class menu
Mov wc.lpszClassName, Offset ClassName ; A pointer to a null-terminated string created by a previous call to the RegisterClassEx function
Push IDI_APPLICATION ; Push default application icon vlaue onto stack
Push NULL ; A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded
Call LoadIcon ; Load standard application icon
Mov wc.hIcon, Eax ; Load Icon into window instance
Mov wc.hIconSm, Eax ; Load small icon into app instance
Push IDC_ARROW ; Push standard arrow icon value onto stack
Push NULL ; A handle to an instance of the module whose executable file contains the cursor to be loaded. NULL if using standard cursors
Call LoadCursor ; Loads the specified cursor resource from the executable file associated with an application instance.
Mov wc.hCursor, Eax ; Load cursor handle into app instance
Lea Ecx, wc ; Load Effetive Address of wc object into Ecx Register
Push Ecx ; Push value of wc address onto stack from Ecx register
Call RegisterClassEx ; 5 - Regisater the window instance
; Create the window using the newly created app instance wc
Push NULL ; Optional pointer to a data structure passed to the window. This is used by MDI window to pass the CLIENTCREATESTRUCT data.
Push hInst ; The instance handle for the program module creating the window.
Push NULL ; A handle to the window's menu. NULL if the default class menu is to be used.
Push NULL ; A handle to the window's parent window if it exists, NULL if not
Push 500 ; The height of the window - CW_USEDEFAULT tells windows to decide
Push 350 ; The width of the window - CW_USEDEFAULT tells windows to decide
Push CW_USEDEFAULT ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push CW_USEDEFAULT ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push WS_OVERLAPPEDWINDOW ; Style of the window - The most common window style is WS_OVERLAPPEDWINDOW.
Push Offset AppName ; Address of the ASCIIZ string containing the name of the window. It'll be shown on the title bar of the window
Push Offset ClassName ; Address of the ASCIIZ string containing the name of window class you want to use as template for this window
Push WS_EX_CLIENTEDGE ; Extended Window Stye - The window has a border with a sunken edge.
Call CreateWindowEx ; 6 - Creatw Window Object
Mov hwnd, Eax ; Copy created window handle to hwnd object
Push SW_SHOWNORMAL ; Activates and displays a window. Use this value if window is displayed for the first time
Push hwnd ; Push the created window handle onto the stack
Call ShowWindow ; 7 - Display the window on screem
Push hwnd ; Push the created window handle onto the stack
Call UpdateWindow ; 8 - Update the window using associated window handle
; Enter a while loop that waits for and responds to messages sent to and from the window such as keyboard input
.WHILE TRUE ; While GetMessage returns TRUE
Push 0 ; The integer value of the highest message value to be retrieved from the range of retrieved messages
Push 0 ; The integer value of the lowest message value to be retrieved from the range of retrieved messages
Push NULL ; Window handle whose messages are to be retrieved. If NULL messages for all current thread windows and any messages for windows whose hend is NULL
Lea Ecx, msg ; Load Effective Address of msg Object
Push Ecx ; Push address of msg Object onto stack
Call GetMessage ; Acquires next message from windows, loads into msg object and runs WndProc
.BREAK .IF (!Eax) ; Break if GetMessage returns FALSE
Lea Ecx, msg ; Load Effective Address of msg Object
Push Ecx ; Push address of msg Object onto stack
Call TranslateMessage ; Transaltes keyboard input and generates a new message (WM_CHAR). This message contains the ASCII value for the key pressed. You can omit this call if your program doesn't process keystrokes.
Lea Ecx, msg ; Load Effective Address of msg Object
Push Ecx ; Push address of msg Object onto stack
Call DispatchMessage ; DispatchMessage sends the message data to the window procedure responsible for the specific window the message is for. In our case, EditBox when we type and Button when we press the button
.ENDW
Mov Eax, msg.wParam ; Return value from WNDCLASSEX loaded into Eax for return to app
Ret ; Return
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
;WndProc rns as part of the GetMessage Call
.IF uMsg==WM_DESTROY ; User clses app
Push NULL
Call PostQuitMessage ; Posts the WM_QUIT message to the message loop causing GetMessage() to return FALSE and stop processing messages
.ELSEIF uMsg==WM_CREATE ; Called when Main window s creatd - create Controls attached to main window
;Display Screen
Push NULL ; Optional pointer to a data structure passed to the window. This is used by MDI window to pass the CLIENTCREATESTRUCT data.
Push hInstance ; The instance handle for the program module creating the window.
Push EditID ; A handle to the window's menu. NULL if the default class menu is to be used.
Push hWnd ; A handle to the window's parent window if it exists, NULL if not
Push 60 ; The height of the window - CW_USEDEFAULT tells windows to decide
Push 240 ; The width of the window - CW_USEDEFAULT tells windows to decide
Push 35 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push 40 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL ; Style of the window
Push NULL ; Address of the ASCIIZ string containing the name of the window.
Push Offset EditClassName ; Address of the ASCIIZ string containing the name of window class you want to use as template for this window
Push WS_EX_CLIENTEDGE ; Extended Window Stye - The window has a border with a sunken edge.
Call CreateWindowEx ; Create the Edit Box
Mov hwndEdit, Eax ; Move handle for EditBox into hwndEdit HWND Object
;Push hwndEdit
;Call SetFocus ; Give Edit Box Focus upon App starting
;Number 0
Number0:
mov esi, ButtonZeroID
mov eax, hWnd
mov edx, 300 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 40 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button0
call Create_Button
;Number 1
Number1:
mov esi, ButtonOneID
mov eax, hWnd
mov edx, 240 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 40 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button1
call Create_Button
;Number 2
Number2:
mov esi, ButtonTwoID
mov eax, hWnd
mov edx, 240 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 100 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button2
call Create_Button
;Number 3
Number3:
mov esi, ButtonThreeID
mov eax, hWnd
mov edx, 240 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 160 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button3
call Create_Button
;Number 4
Number4:
mov esi, ButtonFourID
mov eax, hWnd
mov edx, 180 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 40 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button4
call Create_Button
;Number 5
Number5:
mov esi, ButtonFiveID
mov eax, hWnd
mov edx, 180 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 100 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button5
call Create_Button
;Number 6
Number6:
mov esi, ButtonSixID
mov eax, hWnd
mov edx, 180 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 160 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button6
call Create_Button
;Number 7
Number7:
mov esi, ButtonSevenID
mov eax, hWnd
mov edx, 120 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 40 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button7
call Create_Button
;Number 8
Number8:
mov esi, ButtonEightID
mov eax, hWnd
mov edx, 120 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 100 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button8
call Create_Button
;Number 9
Number9:
mov esi, ButtonNineID
mov eax, hWnd
mov edx, 120 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 160 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset Button9
call Create_Button
;Plus
Plus_Bt:
mov esi, ButtonPlusID
mov eax, hWnd
mov edx, 120 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 220 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonPlus
call Create_Button
;Minus
Minus_Bt:
mov esi, ButtonMinusID
mov eax, hWnd
mov edx, 180 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 220 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonMinus
call Create_Button
;Multiply
Multiply_Bt:
mov esi, ButtonMultiplyID
mov eax, hWnd
mov edx, 240 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 220 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonMultiply
call Create_Button
;Divide
Divide_Bt:
mov esi, ButtonDivideID
mov eax, hWnd
mov edx, 300 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 220 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonDivide
call Create_Button
;Clear
Clear_Bt:
mov esi, ButtonClearID
mov eax, hWnd
mov edx, 300 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 100 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonClear
call Create_Button
;Equal
Equal_Bt:
mov esi, ButtonEqualID
mov eax, hWnd
mov edx, 300 ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov edi, 160 ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
mov ecx, offset ButtonEqual
call Create_Button
.ELSEIF uMsg==WM_COMMAND ; Window receives a message from Windows
mov eax, wParam
.IF lParam == 0
.IF ax == IDM_ZERO
ZERO:
xor ebx, ebx
mov bl, 30h
call Display_Number
.ELSEIF ax == IDM_ONE
ONE:
xor ebx, ebx
mov bl, 31h
call Display_Number
.ELSEIF ax == IDM_TWO
TWO:
xor ebx, ebx
mov bl, 32h
call Display_Number
.ELSEIF ax == IDM_THREE
THREE:
xor ebx, ebx
mov bl, 33h
call Display_Number
.ELSEIF ax == IDM_FOUR
FOUR:
xor ebx, ebx
mov bl, 34h
call Display_Number
.ELSEIF ax == IDM_FIVE
FIVE:
xor ebx, ebx
mov bl, 35h
call Display_Number
.ELSEIF ax == IDM_SIX
SIX:
xor ebx, ebx
mov bl, 36h
call Display_Number
.ELSEIF ax == IDM_SEVEN
SEVEN:
xor ebx, ebx
mov bl, 37h
call Display_Number
.ELSEIF ax == IDM_EIGHT
EIGHT:
xor ebx, ebx
mov bl, 38h
call Display_Number
.ELSEIF ax == IDM_NINE
NINE:
xor ebx, ebx
mov bl, 39h
call Display_Number
;Plus
.ELSEIF ax == IDM_PLUS
Plus:
mov esi, 1
call Create_Parameter
.ELSEIF ax == IDM_MINUS
Minus:
mov esi, 2
call Create_Parameter
.ELSEIF ax == IDM_MULTIPLY
Multiply:
mov esi, 3
call Create_Parameter
.ELSEIF ax == IDM_DIVIDE
Divide:
mov esi, 4
call Create_Parameter
.ELSEIF ax == IDM_CLEAR
Clear:
mov ecx, offset K
mov byte ptr [ecx], 0
mov ecx, offset idx
mov byte ptr [ecx], 0
;memset fuction
mov eax, 0
lea edi, buffer
mov ecx, 512
mov ebx, ecx
rep stosb
;Clear text on screen
Push NULL ; Push NULL onto stack
Push hwndEdit ; Push handle of Edit Box onto stack
Call SetWindowText ; Clear EditBox Text
.ELSEIF ax == IDM_EQUAL
Equal:
;Get text from screen for parameter2
Push 20 ; Push chosen size of buffer for Edit Box text onbto stack
Push Offset Para2 ; Push address of Parameter1 for Edit Box text onto stack
Push hwndEdit ; Push handle of Edit Box onto stack
Call GetWindowText ; Save Text to Parameter1
mov ecx, offset Caculate
mov dl, byte ptr [ecx]
cmp dl, 1
jz Plus_Caculate
cmp dl, 2
jz Minus_Caculate
cmp dl, 3
jz Multiply_Caculate
cmp dl, 4
jz Divide_Caculate
Plus_Caculate:
call Plus_Process
jmp Done
Minus_Caculate:
call Minus_Process
jmp Done
Multiply_Caculate:
call Multiply_Process
jmp Done
Divide_Caculate:
call Divide_Process
jmp Done
Done:
push offset result
push hwndEdit
call SetWindowText
;memset fuction
mov eax, 0
lea edi, Para1
mov ecx, 20
mov ebx, ecx
rep stosb
;memset fuction
mov eax, 0
lea edi, Para2
mov ecx, 20
mov ebx, ecx
rep stosb
Push 20 ; Push chosen size of buffer for Edit Box text onbto stack
Push Offset Para1 ; Push address of Parameter1 for Edit Box text onto stack
Push hwndEdit ; Push handle of Edit Box onto stack
Call GetWindowText ; Save Text to Parameter1
;memset fuction
mov eax, 0
lea edi, buffer
mov ecx, 512
mov ebx, ecx
rep stosb
;memset fuction
mov eax, 0
lea edi, result
mov ecx, 512
mov ebx, ecx
rep stosb
;reset idx
mov esi, offset idx
mov byte ptr [esi], 0
.ELSE ; Any other message ID
Push hWnd ; Push handle to main window onto stack
Call DestroyWindow ; Sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate and destroy it
.ENDIF
.ELSE
.IF ax == ButtonZeroID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_ZERO ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonOneID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_ONE ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonTwoID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_TWO ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonThreeID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_THREE ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonFourID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_FOUR ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonFiveID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_FIVE ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonSixID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_SIX ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonSevenID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_SEVEN ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonEightID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_EIGHT ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonNineID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_NINE ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
;Button for caculate
.ELSEIF ax == ButtonPlusID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_PLUS ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonMinusID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_MINUS ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonMultiplyID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_MULTIPLY ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonDivideID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_DIVIDE ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonClearID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_CLEAR ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ELSEIF ax == ButtonEqualID
shr eax, 16
.IF ax == BN_CLICKED
Push 0 ; lParam
Push IDM_EQUAL ; wParam
Push WM_COMMAND ; The message to be sent
Push hWnd ; The handle to the window that will recieve the message
Call SendMessage ; Send the message WM_COMMAND with lParam = 0 and wParam = IDM_GETTEXT to the main window
.ENDIF
.ENDIF
.ENDIF
.ELSE
Push lParam ; lParam
Push wParam ; wParam
Push uMsg ; The message to be processed
Push hWnd ; Push the handle to the main window onto the stack
Call DefWindowProc ; Calls the default window procedure to provide default processing for any window messages that an application does not process
Ret ; Returns from the WndProc function
.ENDIF
Xor Eax, Eax ; Set Eax to 0
Ret ; Returns from the WndProc function
WndProc endp
Create_Parameter proc
xor edx, edx
mov edx, esi
mov ecx, offset Caculate
mov byte ptr [ecx], dl; ID of plus
;check amount of current parameters
xor edx, edx
mov ecx, offset K
mov dl, byte ptr [ecx]
mov edi, edx
cmp dl, 0
jz Take_Parameter
jmp Get_out ; if we have one, we will exit
Take_Parameter:
Push 20 ; Push chosen size of buffer for Edit Box text onbto stack
Push Offset Para1 ; Push address of Parameter1 for Edit Box text onto stack
Push hwndEdit ; Push handle of Edit Box onto stack
Call GetWindowText ; Save Text to Parameter1
; Push MB_OK ; Push type oif butons for message box onto sack
; Push Offset AppName ; Push address of application name onto stack
; Push Offset Para1 ; Push address of buffer for Edit Box text onto stack
; Push NULL ; Push handle to parent window onto stack
; Call MessageBox ; MessageBox buffer
;take amount current parameter
mov edx, edi
inc edx
mov ecx, offset K
mov byte ptr [ecx], dl
;restart index
mov ecx, offset idx
mov byte ptr [ecx], 0
;memset fuction
mov eax, 0
lea edi, buffer
mov ecx, 512
mov ebx, ecx
rep stosb
Get_out:
;Clear text on screen
Push NULL ; Push NULL onto stack
Push hwndEdit ; Push handle of Edit Box onto stack
Call SetWindowText ; Clear EditBox Text
ret
Create_Parameter endp
Display_Number proc ; display numbers on screen and save them to buffer
xor edx, edx
mov esi, offset idx
mov dl, byte ptr [esi]
mov ecx, offset buffer
mov byte ptr[ecx + edx], bl
inc edx
mov byte ptr [esi], dl
push offset buffer
push hwndEdit
call SetWindowText
ret
Display_Number endp
Create_Button proc
Push NULL ; Optional pointer to a data structure passed to the window. This is used by MDI window to pass the CLIENTCREATESTRUCT data.
Push hInstance ; The instance handle for the program module creating the window.
Push esi ; A handle to the window's menu. NULL if the default class menu is to be used.
Push eax ; A handle to the window's parent window if it exists, NULL if not
Push 60 ; The height of the window - CW_USEDEFAULT tells windows to decide
Push 60 ; The width of the window - CW_USEDEFAULT tells windows to decide
Push edx ; The Y coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push edi ; The X coordinate of the upper left corner of the window - CW_USEDEFAULT tells windows to decide
Push WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON ; Style of the window
Push ecx ; Address of the ASCIIZ string containing the name of the window.
Push Offset ButtonClassName ; Address of the ASCIIZ string containing the name of window class you want to use as template for this window
Push NULL ; Extended Window Stye - The window has a border with a sunken edge.
Call CreateWindowEx ; Create the Button
ret
Create_Button endp
Plus_Process proc
mov ecx, offset Para1
call Ascii_to_Int
mov edi, esi
mov ecx, offset Para2
call Ascii_to_Int
add edi, esi
mov ecx, offset result
call Int_to_Ascii
ret
Plus_Process endp
Minus_Process proc
mov ecx, offset Para1
call Ascii_to_Int
mov edi, esi
mov ecx, offset Para2
call Ascii_to_Int
mov ecx, offset result
cmp edi, esi
jg Positive
jz Equal_Minus
;Negative
mov byte ptr [ecx], 2Dh
inc ecx
sub esi, edi
mov edi, esi
jmp Do_Minus
Equal_Minus:
mov byte ptr [ecx], 30h
ret
Positive:
sub edi, esi
Do_Minus:
call Int_to_Ascii
ret
Minus_Process endp
Multiply_Process proc
mov ecx, offset Para1
call Ascii_to_Int
mov edi, esi
mov ecx, offset Para2
call Ascii_to_Int
xor ebx, ebx
mov ecx, offset result
xor edx, edx
mov eax, edi
mul esi
mov ebx, eax
cmp edx, 0
jz Is_32bit_Num
mov edi, edx ;We had bug here and we must to change Hex to Dec to get true res
call Int_to_Ascii
Is_32bit_Num:
mov edi, ebx
call Int_to_Ascii
ret
Multiply_Process endp
Divide_Process proc
mov ecx, offset Para1
call Ascii_to_Int
mov edi, esi
mov ecx, offset Para2
call Ascii_to_Int
mov eax, edi
div esi
mov ecx, offset result
mov edi, eax
call Int_to_Ascii
ret
Divide_Process endp
Ascii_to_Int proc
xor eax, eax
mov esi, 10
xor ebx, ebx
Atoi_loop:
mov bl, byte ptr [ecx]
xor bh, bh
cmp bl, 0
jz Done_Atoi
sub bl, 30h
mul esi
add eax, ebx
inc ecx
jmp Atoi_loop
Done_Atoi:
xor esi, esi
mov esi, eax
ret