CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2009
    Posts
    100

    Run assembly programs inside microsoft windows?

    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:

    Code:
    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.

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

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Run assembly programs inside microsoft windows?

    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!
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Jun 2009
    Posts
    100

    Re: Run assembly programs inside microsoft windows?

    Quote Originally Posted by S_M_A View Post
    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:

    Code:
    ld program.obj -o program.exe
    However I get this message:

    Code:
    undefined reference to MessageBoxA@16
    How do I include header files using ld?

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Run assembly programs inside microsoft windows?

    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?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Run assembly programs inside microsoft windows?

    Here's an old CG thread http://www.codeguru.com/forum/archiv.../t-355607.html hope it helps
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Run assembly programs inside microsoft windows?

    Quote Originally Posted by S_M_A View Post
    [...] or maybe rename program.obj to program.exe.
    Uuuh, that's pretty darn evil...

    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:

    Code:
        includelib \masm32\lib\user32.lib
    This was MASM, however...

    HTH
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Talking Re: Run assembly programs inside microsoft windows?

    Quote Originally Posted by S_M_A View Post
    Here's an old CG thread http://www.codeguru.com/forum/archiv.../t-355607.html hope it helps
    So many posts for a single-line solution...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  8. #8
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Run assembly programs inside microsoft windows?

    Quote Originally Posted by Eri523 View Post
    So many posts for a single-line solution...
    Yeah, should have googled before doing the first post... Or in a perfect world, the OP would have googled before posting...

    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.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Run assembly programs inside microsoft windows?

    Quote Originally Posted by S_M_A View Post
    Yeah, should have googled before doing the first post... Or in a perfect world, the OP would have googled before posting...
    No, sorry, I didn't mean your posts in this thread here. 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.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured