Click to See Complete Forum and Search --> : Run assembly programs inside microsoft windows?


David2010
October 10th, 2010, 11:07 PM
For the longest time I used linux for writing my assembly programs and it worked perfectly.

My current PC has windows xp on it and is used for both gaming and for assembly programming.

After reading around a bit on windows programming, I made a simple example:



global _WinMain@16

extern _MessageBoxA@16

section .data

parm1 db "Program", 10, 0
parm2 db "Hello World", 10, 0

section .code

_WinMain@16
push 0
push dword parm1
push dword parm2
push 0
call _MessageBoxA@16
add esp, 8
ret 16




It assembles correctly however I have no idea how to link it to an executable.

It only creates an object file once assembled.



nasm -f win32 program.asm -o program.obj

S_M_A
October 11th, 2010, 05:02 PM
I haven't done any assembly programming for a very long time but a shot in the dark would be to remove the -o program.obj or maybe rename program.obj to program.exe. Check if current program.obj starts with MZ!

David2010
October 11th, 2010, 05:33 PM
I haven't done any assembly programming for a very long time but a shot in the dark would be to remove the -o program.obj or maybe rename program.obj to program.exe. Check if current program.obj starts with MZ!

Even if you remove the -o program.obj, it still creates an object file. :-/

I tried to use ld to make an exe such as:



ld program.obj -o program.exe



However I get this message:



undefined reference to MessageBoxA@16



How do I include header files using ld?

S_M_A
October 11th, 2010, 05:44 PM
You don't include headers when linking, you should link with the appropriate lib/obj. Isn't there any documentation regarding how to build a win32 exe with nasm?

S_M_A
October 11th, 2010, 05:47 PM
Here's an old CG thread http://www.codeguru.com/forum/archive/index.php/t-355607.html hope it helps

Eri523
October 11th, 2010, 07:05 PM
[...] or maybe rename program.obj to program.exe.

Uuuh, that's pretty darn evil... :D

No, without kidding, older compilers and assemblers used import libraries (file extension .lib) for that purpose. The only assembly module I ever wrote for the Win environment (that was to be finally assembled into a .dll) includes this line for the purpose in question:


includelib \masm32\lib\user32.lib


This was MASM, however...

HTH

Eri523
October 11th, 2010, 07:06 PM
Here's an old CG thread http://www.codeguru.com/forum/archive/index.php/t-355607.html hope it helps

So many posts for a single-line solution... :D

S_M_A
October 12th, 2010, 02:30 PM
So many posts for a single-line solution... :D
Yeah, should have googled before doing the first post... Or in a perfect world, the OP would have googled before posting... :D

Regarding the rename. It might have been so that the -o option renamed a perfectly good exe output to obj. Just like -o does for gcc (if I remember correct). That's why I asked the op to first look for Mark Zbikowski's initials. :wave:

Eri523
October 12th, 2010, 04:31 PM
Yeah, should have googled before doing the first post... Or in a perfect world, the OP would have googled before posting... :D

No, sorry, I didn't mean your posts in this thread here. :o Instead I meant the archived thread you have linked to...

And I'm not even sure whether my suggestion will help the OP, as I know very little about nasm.

Regarding the rename. It might have been so that the -o option renamed a perfectly good exe output to obj. Just like -o does for gcc (if I remember correct). That's why I asked the op to first look for Mark Zbikowski's initials.

I couldn't imagine any reasonable software might do something like that. Maybe your suggestion actually is the clue that the OP needed. :)