Author Topic: Can nasm make windows programs  (Read 14342 times)

Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
Can nasm make windows programs
« 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

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Re: Can nasm make windows programs
« Reply #1 on: December 07, 2012, 12:35:05 AM »
Yes it is.  Here is a snippet from my NASM programs for windows

Code: [Select]
                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


Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: Can nasm make windows programs
« Reply #2 on: December 07, 2012, 12:36:44 AM »
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.


Offline Fixer

  • Jr. Member
  • *
  • Posts: 11
Re: Can nasm make windows programs
« Reply #3 on: December 07, 2012, 03:47:34 AM »
Thanks to both of you.

I didn't look thru all the examples from NASMX, but later found the windows examples.

Andy