The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Twister on September 12, 2010, 02:40:10 AM

Title: NASM ... ?
Post by: Twister on September 12, 2010, 02:40:10 AM
I thought I would explore other assemblers, and I did find one called NASM.

It assembles great, and I use the ALINK.EXE to link. It's just that every simple PE I make crashes..

prog.asm:
[CPU 486]

[EXTERN ExitProcess]
[EXTERN MessageBoxA]

[GLOBAL _start]

[SECTION CODE USE32 CLASS=CODE]
_start:
        PUSH    DWORD 0
        PUSH    DWORD msg_title
        PUSH    DWORD msg_body
        PUSH    DWORD 0
        CALL    [MessageBoxA]
        PUSH    DWORD 0
        CALL    [ExitProcess]
   
[SECTION DATA USE32 CLASS=DATA]

    msg_body:    DB 'Hello, World!', 0
    msg_title:    DB 'Hello!', 0
Title: Re: NASM ... ?
Post by: japheth on September 12, 2010, 05:34:44 AM
> It assembles great, and I use the ALINK.EXE to link. It's just that every simple PE I make crashes..

Remove the '[]' around the symbols behind CALL.

Nasm is very sensible in this area.

My opinion is: NASM is strong in the (Linux) ELF format, but for DOS and Win32 it is slightly "behind".
Title: Re: NASM ... ?
Post by: Twister on September 12, 2010, 06:01:07 AM
Quote from: japheth on September 12, 2010, 05:34:44 AM
... but for DOS and Win32 it is slightly "behind".

Yeah, I really noticed that. I had to search the entire internet for additional libraries to link to because the win32 installer only came with the assembler and a disassembler.
Title: Re: NASM ... ?
Post by: japheth on September 12, 2010, 06:21:33 AM
Quote from: GTX on September 12, 2010, 06:01:07 AM
Yeah, I really noticed that. I had to search the entire internet for additional libraries to link to because the win32 installer only came with the assembler and a disassembler.

I didn't mean that. IMO it's not the job of an assembler to provide OS-specific libraries.

Examples where NASM is "behind":
- no support for weak externals for OMF or COFF
- no support for a "current" symbolic debug format.
Title: Re: NASM ... ?
Post by: Twister on September 12, 2010, 06:23:59 AM
Well, if they are going to say that their assembler is portable they should put their money where their mouth is and include the target-OS libraries.
Title: Re: NASM ... ?
Post by: Tedd on September 12, 2010, 12:33:24 PM
Portable means it will RUN on other platforms. It's still up to you to do something useful with it :P

As for the value-added components, NasmX may be more appropriate for you -- http://www.asmcommunity.net/projects/nasmx
Title: Re: NASM ... ?
Post by: Twister on September 12, 2010, 03:55:58 PM
Well, after all this I only have one word for NASM:  poor

I have attached a simple msg_box project that crashes no matter what I do. I'll be sticking with MASM from here on out. :U
Title: Re: NASM ... ?
Post by: japheth on September 12, 2010, 04:04:44 PM
Quote from: GTX on September 12, 2010, 03:55:58 PM
I have attached a simple msg_box project that crashes no matter what I do.

The reason for the crash is that the binary has no entry point. Didn't the linker complain?
Title: Re: NASM ... ?
Post by: Twister on September 12, 2010, 06:41:20 PM
Now it works! GoLink puts a lot of junk into my executable though. :'(
Title: Re: NASM ... ?
Post by: Vortex on September 12, 2010, 07:04:12 PM
What's the "junk" ? Did you check the necessary specification before calling it "junk" ?
Title: Re: NASM ... ?
Post by: Twister on September 12, 2010, 07:45:06 PM
(http://i54.tinypic.com/2qxw6s4.png)
Title: Re: NASM ... ?
Post by: ecube on September 12, 2010, 09:34:22 PM
it puts a short message? so what, you can remove it(though I don't know if that goes against GoASM's license or not). Even so it just plugs the free awesome tool you're using alil bit.
Title: Re: NASM ... ?
Post by: Vortex on September 12, 2010, 09:48:36 PM
GTX,

Now, are you able to interpret that hex editor output?

EDIT : This line should be corrected in your souce code :

; golink /console msgbox.obj kernel32.dll user32.dll

Your project is intended as a GUI application, not a console. Specifying the entry point correctly :

golink msgbox.obj /entry _start kernel32.dll user32.dll

The result is an executable of 2048 bytes.

If you link the object file with polink or MS link, the result is 3072 bytes :

\masm32\bin\polink.exe /SUBSYSTEM:WINDOWS /ENTRY:start msgbox.obj \masm32\lib\kernel32.lib \masm32\lib\user32.lib

To understand the secret of the object module msgbox.obj, please run this command :

\masm32\bin\dumpbin /SYMBOLS msgbox.obj >output.txt
Title: Re: NASM ... ?
Post by: Twister on September 13, 2010, 12:25:55 AM
I'm not sure how to you used the polink on msgbox.obj

> \masm32\bin\polink.exe /SUBSYSTEM:WINDOWS /ENTRY:_start msgbox.obj \masm32\lib\kernel32.lib \masm32\lib\user32.lib
>>> POLINK: error: Unresolved external symbol 'MessageBoxA'.
>>> POLINK: error: Unresolved external symbol 'ExitProcess'.
>>> POLINK: fatal error: 2 unresolved external(s).
Title: Re: NASM ... ?
Post by: Vortex on September 13, 2010, 05:27:42 PM
The version of Polink : Pelles Linker, Version 6.00.1  It comes with the latest version of Pelles C development suit. I copied it to my \masm32\bin folder.

Attached is the executable built with Polink and MS Link.