News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

NASM ... ?

Started by Twister, September 12, 2010, 02:40:10 AM

Previous topic - Next topic

Twister

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

japheth

> 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".

Twister

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.

japheth

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.

Twister

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.

Tedd

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
No snowflake in an avalanche feels responsible.

Twister

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

japheth

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?

Twister

Now it works! GoLink puts a lot of junk into my executable though. :'(

Vortex

What's the "junk" ? Did you check the necessary specification before calling it "junk" ?

Twister


ecube

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.

Vortex

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

Twister

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).

Vortex

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.