Our Feeds

Saturday, 16 August 2014

Ajith Kp

Fist GUI Program - FASM

          I hope you have read the previous posts about FASM. Else please read it here: http://terminalcoders.blogspot.in/search/label/FASM.

          I hope most of you are familiar with Visual C++. Otherwise it will be hard to study FASM/MASM. Because you should know the syntax of Visual C++ and how you can convert it to FASM.

          I hope the first GUI program you studied is how to show the MessageBox. Isn't? Now I will explain the important parts of code.



The syntax of MessageBox() in Visual C++ is,

MessageBox(WindowHandle, YourMessage, CaptionOfMessageBox, IconsAndButtons);

           Now we can convert it to FASM,
           The function MessageBox() is declared in user32.dll in Windows OS. When the API function MessageBox() calls, the OS will pass its control to kernel modules where the function is actually declared. So we need to import user32.dll. The last import is ExitProcess() function. This function is declared in kernel32.dll. So kernel32.dll is must be included. The syntax of import part is,

data import
     library kernel32, 'kernel32.dll', user32, 'user32.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import user32, MessageBox, 'MessageBoxA'
end data

           In line ` library import kernel, 'kernel.dll', user32, 'user32.dll' ` the `kernel32` and `user32` are aliasing of long `kernel32.dll` and `user32.dll`. Like wise we have aliased ExitProcess and MessageBoxA.

           The function `invoke` is used to invoke the system calls.

invoke MessageBox, 0, msg, cap, MB_ICONINFORMATION+MB_YESNO

           The full source code is,

format PE GUI 4.0
;
;
; AJITH KP > HTTP://WWW.TERMINALCODERS.BLOGSPOT.DE
;
;
; IMPORTED FROM MY ANOTHER BLOG DSPROGRAMMING.CO.VU
;
include 'win32a.inc'
invoke MessageBox, 0, msg, cap, MB_ICONINFORMATION+MB_YESNO
msg db 'Do you like this blog http://www.dsprogramming.co.vu ???', 0
cap db 'D S', 0
exit:
        invoke ExitProcess
data import
     library kernel32, 'kernel32.dll', user32, 'user32.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import user32, MessageBox, 'MessageBoxA'
end data

           Now check the size of programs in both FASM and Visual C++ of same program.
In FASM
In Visual C++

           The size of program in FASM is only 1 KB, but the program in Visual C++ is about 27 KB. So the program in ASM will execute more rapidly than programs in C++ or any other programming languages. So that ASM is used to create device drivers, game modules, even computer viruses!!!.
           Hope you like this post. Please share with you friends who is interested in it.