News:

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

Trying to get started

Started by gbdick, June 14, 2005, 01:59:46 AM

Previous topic - Next topic

gbdick

I am trying to assemble and link without actually doing anything.

At this point I just want to get the tools to work.

Obviously I am missing something important.


C:\PROGRA~1\MICROS~3\VC98\Bin>type test1.asm
.386
.model flat
.data
.code
start:
end start

C:\PROGRA~1\MICROS~3\VC98\Bin>ml /c test1.asm
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: test1.asm

C:\PROGRA~1\MICROS~3\VC98\Bin>link test1.obj
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

test1.obj : warning LNK4033: converting object format from OMF to COFF
LINK : fatal error LNK1561: entry point must be defined

C:\PROGRA~1\MICROS~3\VC98\Bin>

GregL

gbdick,

You need to specify a calling convention.

.model flat,stdcall

It will assemble and link if you do that.


Phil

Welcome to the forum! I'm also fairly new here but I think this might help. These are the commands I use for command line applications:
ml    /c /coff /Cp /Zi /Zd MyProg.asm
link  /debug /subsystem:console MyProg.obj


 /coff option produces a coff object file automatically and avoid the conversion message from the linker.
 /Cp option allows case sensitive labels and symbols to be used and passed to the linker
 / Zi and /Zd tell ml to include ouput for the debugger in the object file

 /debug tells link to include all symbols and labels in the exe file
 /subsystem:console creates a command line application

I'm not sure but, I think the default is /subsystem:windows which might be looking for an entry label named WinMain. I think you have the right idea and just adding the /subsystem:console option to your link command will probably produce a non-functional exe for you!

I'd also suggest having a look at the help menu in the MASM32 editor, qeditor.exe, that probably came with the masm32 installation.

Jeff

Quote from: Greg on June 14, 2005, 02:14:23 AM
gbdick,

You need to specify a  calling convention.

.model flat,stdcall

It will assemble and link if you do that.


not necessarily.  if it was left out, he would need to have his entry to begin with an underscore.  :bg  however, to further complicate things, since the program was meant to be linked, an ExitProcess call is required otherwise there will be an error when running the "program".  but doing so would require the use of the Kernel32 library.  should work fine after a few adjustments:.386
.model flat
ExitProcess proto stdcall, :dword
includelib \masm32\lib\kernel32.lib
.data
.code
_start:
invoke ExitProcess,0
end _start
or if you really want:.386
.model flat,stdcall
ExitProcess proto, :dword
includelib \masm32\lib\kernel32.lib
.data
.code
start:
invoke ExitProcess,0
end start
if you wanted to do away with the includelib part, you would have to make the adjustments in the link command.  building on phil's handywork  :wink :ml    /c /coff /Cp /Zi /Zd test1.asm
link  /debug /subsystem:console test1.obj \masm32\lib\kernel32.lib

GregL

Jeff,

Picky, picky. But good point. :bg  I didn't try running it.


hutch--

gb,

While there are a mountain of ways to get output from MASM, there is some sense in using well tested and flexible techniques. Here is the very basic stuff.


      .486                      ; create 32 bit code
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive


The processor specification excludes anything from a processor above it so if you need instructions from a later processor, you use a higher spec.

The ".model flat" is required by 32 bit Windows because it runs a FLAT memory model. The vast majority of Windows API calls are STDCALL so you save yourself a lot of grief by specifying STDCALL. You can use procedure with a C calling convention with no problems as long as they are specified as C in their prototype.

The important one is setting the names as case sensitive otherwise you cannot use the API functions wich are all case sensitive. Without this if you try to build a program and you will get the standard "error count exceeds 100" effect.

ML 6.15 is a very reliable version that also supports SSE2 but if you are going to use the VC98 linker, look up the alignment specs for it as VC uses different alignment than MASM and it will blow out the size of your EXE/DLL files.

It is worth you getting the MASM32 project as it has a very comprehensive set of include files and recently the prototypes for the MSVCRT library as well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

tenkey

I believe the OMF-to-COFF converter ignores the start address supplied by END. I know that when I used an OMF assembler, I always needed to add the /ENTRY option to the linker command.

Assembling directly to COFF format may solve that problem.

ml /c /coff test1.asm
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

gbdick

Thanks for the help everyone.

I was able to get it to work.

C:\masm32\bin>type test2.asm
.486
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
MsgCaption      db "Test",0
MsgBoxText      db "Test",0
.code
start:
        invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
        invoke ExitProcess,NULL
end start

C:\masm32\bin>ml /c /Cp /coff test2.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: test2.asm

C:\masm32\bin>link /subsystem:windows test2.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


C:\masm32\bin>test2

(at this point the message box displayed, and clicking ok terminated the program)

C:\masm32\bin>