News:

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

ml.exe on x86_64

Started by patfla, October 15, 2010, 02:45:37 AM

Previous topic - Next topic

patfla

I may need to do some assembly on x86_64 with VS 2008 and wanted to see how this environment works for assembler.

The assembler itself seems to be ml.exe and not (or no longer) masm.exe.  Found this piece of sample code: 


; requires /coff switch on 6.15 and earlier versions
.386
.model small,c
.stack 100h
.data
    msg db "Hello World!",0
.code
    INCLUDELIB MSVCRT
    EXTRN printf:NEAR
    EXTRN exit:NEAR
PUBLIC main
main PROC
    mov eax, offset msg
    push eax
    call printf
    mov eax,0
    push eax
    call exit
main ENDP
END main


The .386 and other things undoubtedly indicate the code is old.  Let's see if it works.

It appears to compile with ml


d:\Projects\Masm>ml hw.asm
Microsoft (R) Macro Assembler Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: hw.asm
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/OUT:hw.exe
hw.obj

d:\Projects\Masm>


Run it.  What's an R6034 runtime error?  Google – oh I need a manifest.  I'd rather not have to screw with this, but whatever, I suppose it's for the greater good of the world.

Fumble around and cobble together the following:


d:\Projects\Masm>type hw.manifest
Executable: hw.exe
Manifest:hw.exe.manifest
Sample application manifest file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86_64"
     name="hw"
     type="win32"/>
  <description>Description of your application</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

d:\Projects\Masm>


And mt.exe works


d:\Projects\Masm>mt.exe -manifest hw.manifest -outputresource:hw.exe;1
Microsoft (R) Manifest Tool version 5.2.3790.2076
Copyright (c) Microsoft Corporation 2005.
All rights reserved.

d:\Projects\Masm>


Now when I run, I get


d:\Projects\Masm>hw
The application has failed to start because its side-by-side configuration is in
correct. Please see the application event log or use the command-line sxstrace.e
xe tool for more detail.

d:\Projects\Masm>


Side-by-side error: that's 32/64 bit confusion.

I've been doing all this in a 32 bit cmd (from c:\windows\syswow64).

So strictly speaking this isn't an assembly question as such but maybe it has something to do with the link that's embedded in ml.exe?  Or maybe it has something to do with my manifest file where, manifestly, I don't really know what I'm doing.

patfla

Woops.  This is a masm forum as in

http://masm32.com/

and not ml.exe.

Sorry.

hutch--

Your problem is you have mixed real mode and protected mode code.


.model small,c
.stack 100h


This is DOS code that does not work in 32 bit protected mode.

Try .model FLAT, STDCALL

Do not use the ".stack line.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth

Quote from: hutch-- on October 15, 2010, 03:35:15 AM
Your problem is you have mixed real mode and protected mode code.

Hm, I successfully assembled, linked and ran it as a Win32 binary - without modifying the source. So I guess it is NOT "real mode code".

The ".model small" and ".stack" lines are uncommon for Win32, but they don't hurt. The stack size is ignored by the MS COFF linker.

It's a good idea, however, to use the -coff switch ( as suggested in the source ):

ml -c -coff hw.asm

What's also important: to use a REASONABLE version of msvcrt.lib. That is, don't use one of the versions coming with MS VC 2005, 2008, 2010,...! Use an older one, or create your own one.

patfla

Quote from: japheth on October 15, 2010, 04:02:41 AM
Quote from: hutch-- on October 15, 2010, 03:35:15 AM
Your problem is you have mixed real mode and protected mode code.

Hm, I successfully assembled, linked and ran it as a Win32 binary - without modifying the source. So I guess it is NOT "real mode code".

The ".model small" and ".stack" lines are uncommon for Win32, but they don't hurt. The stack size is ignored by the MS COFF linker.

It's a good idea, however, to use the -coff switch ( as suggested in the source ):

ml -c -coff hw.asm

What's also important: to use a REASONABLE version of msvcrt.lib. That is, don't use one of the versions coming with MS VC 2005, 2008, 2010,...! Use an older one, or create your own one.


thanx to both of you.

japheth> ml -c compiles only - no link.  How then do I link this?


d:\Projects\Masm>link hw5.obj
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1221: a subsystem can't be inferred and must be defined

d:\Projects\Masm>


I think what this means is that ml.exe needs to be told where msvcrt.lib is located.

japheth


> How then do I link this?

1. get a "good" msvcrt.lib. You may use the one included in Masm32.
2. enter "link hw.obj /subsystem:console"


patfla

Quote from: japheth on October 15, 2010, 04:56:57 AM

> How then do I link this?

1. get a "good" msvcrt.lib. You may use the one included in Masm32.
2. enter "link hw.obj /subsystem:console"



That worked - thanx. 

I guess the previous need for a manifest was a function of current msvcrt.lib's (vc 2003 and up?) and since the msvcrt.lib I just used was built when I installed masm32 a couple of minutes ago, it doesn't need a manifest (?).  Which doesn't have much to do with assembly but is an issue on Windows 7 where assembly programs I write will have to build and run (unless I use masm32 but I'm not sure yet that will be an option).

GregL

Quote from: patflaI guess the previous need for a manifest was a function of current msvcrt.lib's (vc 2003 and up?) and since the msvcrt.lib I just used was built when I installed masm32 a couple of minutes ago, it doesn't need a manifest (?).

Yes, in VS 2005  and later msvcrt.lib refers to msvcr80.dll, msvcr90.dll etc. which are "side-by-side" DLLs, which require a manifest.

Quote from: patflaWhich doesn't have much to do with assembly but is an issue on Windows 7 where assembly programs I write will have to build and run (unless I use masm32 but I'm not sure yet that will be an option).

MASM32 works fine on Windows 7.


Regarding your original question, if you want to assemble x64 code, the (Microsoft) assembler is ml64.exe.  Take a look in the 64-bit sub-forum.

patfla

ml64.exe >  thanx Greg.

But back to 32 bits for a moment.  Are the directives supported by http://masm32.com/index.htm the same as MS, as detailed here I think:

http://msdn.microsoft.com/en-us/library/8t163bt0%28VS.80%29.aspx

Trying to get a better fix on how the masm32 project independent of MS relates to MS's own assemblers.