NASM - The Netwide Assembler
NASM Forum => Example Code => Topic started by: Fixer on December 06, 2012, 11:27:28 PM
-
I installed nasm.
Can it make Windows programs that have message boxes etc ?
I did not see any code in the examples.
Are there batch files to make assembling and compiling easier ?
When I ran the bat file to make one of the demos, there was no .exe.
Thanks,
Andy
-
Yes it is. Here is a snippet from my NASM programs for windows
push ecx ; 5 : "X" Position
push WS_STYLE ; 4 : dwStyle
push AppTitle ; 3 : lpWindowName
push AppName ; 2 : lpClassName
push WS_EX_STYLE ; 1 : dwExStyle
call _CreateWindowExA@48 ; USER32
add esp, 20 ; Waste uncessary space
mov ebx, esp
or eax, eax ; Was a handle returned
jnz .Pump ; Drop into message pump if so
lea esp, [ebp-16] ; Point to values established earlier
call Ext_Error ; Promp operator with error
jmp .Done ; Ignore value returned, exit procedure
; Applications primary message pump
.Pump xor eax, eax
push eax ; 4 : wMsgFilterMax
push eax ; 3 : wMsgFilterMin
push eax ; 2 : hWnd
push ebx ; 1 : lpMsg
call _GetMessageA@16 ; USER32
or eax, eax ; Test return value
jz .Done ; ZR=1, WM_QUIT
push ebx ; 1 : lpMsg
call _TranslateMessage@4 ; USER32
push ebx ; 1 : lpMsg
call _DispatchMessageA@4 ; USER32
jmp .Pump ; Continue
.Done leave ; Kill procedure frame
pop edi
pop ebx ; and essential registers used by procedure
ret
-
Of course NASM can create Windows Apps! There are a few differences between NASM and MASM. 2 of the big ones:
1. NASM does not have high level macros like NASM
2. we use brackets around variable names to access the data
MyVar is defined as a dword and has a value of 123 and a starting address of 40000
MASM:
mov eax, MyVar ; eax == 123
mov eax, offset MyVar ; eax == 40000
NASM:
mov eax, [MyVar] ; eax == 123
mov eax, MyVar ; eax == 40000
there is no offset or addr operators in NASM. There are a quite a few differences, but one you learn them, NASM is a bit easier to use and understand.
If you want to go the route of macros and all (most) of the window defines, there is NASMX, take a look at that also.
I have written a few NASM tutorials, you can find them here http://www.dreamincode.net/?p=kudos&kudosmember=495049
MASM:
invoke MessageBox, NULL, offset Hello, offset Grrrr, MB_OK
NASM:
push MB_OK
push Grrr
push Hello
push NULL
call MessageBoxA/W
you would %define MessageBox box to be the A or W version.
-
Thanks to both of you.
I didn't look thru all the examples from NASMX, but later found the windows examples.
Andy