Showing posts with label FASM. Show all posts

Fist GUI Program - FASM

          I hope you have read the previous posts about FASM. Else please read it here: http://www.dsprogramming.co.vu/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.DATASTRUCTURESANDPROGRAMMING.BLOGSPOT.DE
;
;
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.

Hello World in FASM

          `Hello World` is the first program to implement in every programming languages. Here it is going to implement first application in FASM.


format PE console
include 'win32a.inc'
;
;
; AJITH KP > HTTP://WWW.DATASTRUCTURESANDPROGRAMMING.BLOGSPOT.DE
;
;
invoke printf, hello
invoke getch
invoke ExitProcess, 0
hello db 'Hello World!!!', 0
data import
     library kernel32, 'kernel32.dll', msvcrt, 'msvcrt.dll'
     import kernel32, ExitProcess, 'ExitProcess'
     import msvcrt, printf, 'printf', getch, '_getch'
end data

FASM Begins

          FASM is an extend of MASM. Like MASM you can use FASM. I like FASM more than MASM because it provides an environment for developing which is easier than MASM. The FASM stands for Flat Assembler.
          Download Linkhttp://flatassembler.net/download.php
     

          You can use FASM for developing applications which will execute faster than that of created by other languages like C++, C#, etc. Because assembly languages is very small in size and uses bare system calls.
So that the game developers still using assembly codes to develop the modules which should load more fast.

          I hope you understand the importance of assembly language and why it is still alive. :)