News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Quick MASM Prompt Setup Question

Started by Undefined_Behavior, September 12, 2013, 01:31:29 PM

Previous topic - Next topic

Undefined_Behavior

Hello Masm forum posters, I have a little question:

I'm learning from a book called "Assembly Language for x86 Processors, 6th edition". My problem is that I want to setup MASM manually by compiling from prompt with makefiles and such rather than importing an "existing file" in Visual Studio.

Currently learning to navigate the command line and have learned c++ basically from the g++ compiler. For some reason even with experience using third party libs I'm still not able to get my setup correct.

Could someone please guide me through each step or give me advice for setting this up?

Basically this is what I've done so far:
Downloaded MASM.
Set MASM's bin folder to my path as C:\masm32\bin;
Downloaded the Irvine zip for visual studio 2010 under this link: http://asmirvine.com/ and extracted it to the folder C:\Irvine.

From here is where the problems began. First the source:
TITLE MASM Template (main.asm)

; Description:
;
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "MASM program example",0dh,0ah,0


.code
main PROC
call Clrscr 

mov edx,offset myMessage
call WriteString

exit
main ENDP

END main


And now here is what I've tried:
First I tried to just compile away without setting the include or lib folders. This consisted of the simple command:
ml main.asm

   and of course this failed as: main.asm(7) : fatal error A1000: cannot open file : Irvine32.inc

   so I set the include and lib variables to C:\Irvine. Recompile...
                                               ml main.asm
                                               main.asm(7) : fatal error A1000: cannot open file : Irvine32.inc


   so I thought naturally I might need to include the lib and try some sort of link command so I added Irvine32.lib....
                                             ml main.asm /link Irvine32.lib
                                               main.asm(7) : fatal error A1000: cannot open file : Irvine32.inc
                                               ml main.asm Irvine32.lib
                                               main.asm(7) : fatal error A1000: cannot open file : Irvine32.inc


So yea...the problem is obvious what I don't find obvious is the reason/solution. Any help would be greatly appreciated.

Undefined_Behavior

Really dumb mistake...
I included C:\Irvine in the include and lib environment variables as C:Irvine instead of C:\Irvine.
Unfortunately this is not the end of my troubles as now I'm having a linking problem:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: main.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/z2
"main.obj"
"main.exe"
NUL
LINK : warning LNK4044: unrecognized option "z2"; ignored
main.obj : warning LNK4033: converting object format from OMF to COFF
LINK : fatal error LNK1181: cannot open input file "main.exe"

dedndave

try this
        INCLUDE    C:\Irvine\Irvine32.inc
        INCLUDELIB C:\Irvine\kernel32.lib
        INCLUDELIB C:\Irvine\user32.lib

;#######################################################################

        .DATA

szTest  db 'Test',0

;#######################################################################

        .CODE

;***********************************************************************

_main   PROC

        INVOKE  MessageBox,NULL,offset szTest,offset szTest,MB_OK
        exit

_main   ENDP

;#######################################################################

        END     _main


you may have to adjust the INCLUDE and INCLUDELIB paths

this is a windows program, so.....
\masm32\bin\ml /c /coff MyFile.asm
\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF MyFile.obj

Undefined_Behavior

#3
That ran successfully but only once I used:

C:\masm32\bin\Link /SUBSYSTEM:WINDOWS /OPT:NOREF main.obj         instead of:
\masm32\bin\ml\link /SUBSYSTEM:WINDOWS /OPT:NOREF main.obj    EDIT: Just realized I read your post wrong and you never had ml

your path yielded: The system cannot find the path specified.
which would make sense since I have no \masm32\bin\ml folder.


From here how would I get my own program to run, preferably without adding include directives? (directives? right? sorry kinda new to this).

jj2007

#4
The Masm32 package is more powerful than the Irvine library, but you can use them in parallel. Here is a simple example which uses one extra include file from the MasmBasic library, Irvine32Mb.inc

Note there is no need for any environment variables. It runs out of the box with \Masm32\qeditor.exe's "Console Build All".

include \masm32\include\masm32rt.inc
include \masm32\MasmBasic\IrvineMb\Irvine32Mb.inc ; needed to build Irvine's (many but not all) 32-bit examples

.code
start:
mov eax, 11111111h ; in \Masm32\qeditor.exe, use "Project/Console build all", then "Project/Run Program"
mov ebx, 22222222h ; in \Masm32\RichMasm\RichMasm.exe, just hit F6 (detects console mode automatically)
mov ecx, 33333333h
mov edx, 44444444h ; load regs with hex values
call DumpRegs ; DumpRegs displays the regs in hexadecimal format
call DumpRegs ; call again to show that DumpRegs did not change any register
inkey "ok?"
exit
end start


EDIT: New attachment - the lib and macro files were missing.

Undefined_Behavior

Although I know I can use the QEditor (or Visual Studio as my class is doing) I'd prefer to run it from the prompt as I'm trying to rope in all my programming languages under one working environment (sublime text 2 and command prompt). My question still stands as how do I get the program (written by Irvine posted above) to work; bypassing the error stated (and perhaps understanding why and how to correct it).

Thought I should note also that when I tried to run your program from the prompt with ml main.asm I got the following error:
main.asm(2) : fatal error A1000: cannot open file : \masm32\MasmBasic\IrvineMb\Irvine32Mb.inc

I'm assuming this is because masm32 does not by default come with MasmBasic (I'm assuming that's a third party library? sorry still a beginner just getting started with masm).

jj2007

Quote from: Undefined_Behavior on September 12, 2013, 05:26:15 PMcannot open file : \masm32\MasmBasic\IrvineMb\Irvine32Mb.inc

There is an attachment to my above post. Unzip to C:\ with "use folder names".

Undefined_Behavior

One fatal error after the next. Here is what I got this time:
\masm32\MasmBasic\IrvineMb\Irvine32Mb.inc(5) : fatal error A1000: cannot open file : \masm32\MasmBasic\IrvineMb\IrvineSmallWinMb.inc

Unfortunately, even if I solve this problem I fail to see how it is related with a:
LINK : warning LNK4044: unrecognized option "z2"; ignored
main.obj : warning LNK4033: converting object format from OMF to COFF
LINK : fatal error LNK1181: cannot open input file "main.exe"

error.

jj2007

You need the right commandlines. Here they are:
\masm32\bin\ml /c /coff main.asm
\masm32\bin\link main.obj


ttt is a good lecture, too.

Welcome to the Forum - why do you want to learn assembler? Few people do this nowadays...

dedndave

it would seem that you have a path conflict
because your environment is set up for C, it may be that the build is becoming a little confused

as you can see, we have not applied a z2 option, anywhere   :P
and, we use the /coff switch on the ML command line to create COFF object modules, not OMF

when you build from the QEditor program using the menu commands,
the batch files that are in the masm32\bin folder are used to perform the different build types
you can use the same batch files from the command prompt to save some typing
also, you can examine those batch files to see the command lines used
either way, you want the LINK switches to match an ASM build, not a C build

Jochen has shown you that the masm32 libraries may be used, rather than Kip Irvine's libraries
as he mentioned, the masm32 libraries are much more comprehensive
and - most forum members are not too familiar with Kip's libraries

however, that does not help you with what you are trying to achieve - lol

i haven't played with Kip's libraries much, lately
it would help us if we knew what folders the following files are in:
Irvine32.inc
SmallWin.inc
Macros.inc
GraphWin.inc
VirtualKeys.inc

kernel32.lib
User32.lib
Irvine32.lib


there are also Irvine16.inc and Irvine16.lib files, for building 16-bit programs

the Irvine32.inc file has include directives for SmallWin.inc and VirtualKeys.inc
but, i don't find the includelib directives in Irvine32 or SmallWin to include the import libraries mentioned above
you may have a newer version of Kip's libraries, that take care of that
so, you have to be aware of what files are already included
at the end of the day, the import libraries are needed to build programs

so - it may be that Kip's book tells you to set certain environment variables
they may conflict with the environment variables for VS
(the masm32 package is set up to not use environment paths)
and - you can set the variables in the build batch file to overcome this
that way, the environment variables are only changed for the life of the console window
these variables can set up the default folders for include files and import libraries

qWord

Quote from: Undefined_Behavior on September 12, 2013, 05:26:15 PMMy question still stands as how do I get the program (written by Irvine posted above) to work
you can specify the libraries also on the command line either as full path, or relative to the current LIBPATH.
In the attachment 3 build files, which shows some variations (extract the archive to a folder on the same drive as the MASM32 and Irvine installation).
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

also.....
while the Irvine libraries may be used with the masm32 libraries, that is just going to confuse things for you
i believe Kip's package includes ML v6.15 and a linker
so - try to get set up to build using those
forget about masm32, for now

if you look at Kip's package, he may have provided batch files that take care of all this   :t

when you get to the end of the semester, you will probably be expected to write a program using Irvine32   :biggrin:
Kip's functions do not always follow the ABI, at least not the way the forum members are used to

dedndave

ok....
i went to Kip's site and downloaded the package for VS 2010
i don't have VS 2010, nor do i have Kip's book to read
but, at least i know the paths for the files - lol

i am guessing that the book tells you how to get set up to use the ML and LINK programs in VS 2010
most forum members are not going to have good answers for what you want   :redface:

if you want to get set up to build from the command line - not VS,
you may want to write a couple batch files
the ones qWord has provided may be very helpful

Undefined_Behavior

Just like to say thank you to everyone and especially a huge thanks to qWord. It worked after running build1.bat. I then trimmed it down since I had my lib and include environment variables set to C:\Irvine to:
ml /c /coff main.asm
link /SUBSYSTEM:CONSOLE Irvine32.lib Kernel32.lib User32.lib

I appreciate the example that jj2007 was trying to set by showing that we can (and I know should) try to program natively from masm libraries (and should for performance) but unfortunately as dedndave said that won't help me for my class. Despite this I've taken it upon myself to learn to compile and link it manually through prompt.

I have a couple more question(s) for clarification if I haven't driven everyone insane yet. What does the default ml file.asm command with no switches actually do? What are OMF and COFF object modules? Why does ml invoke a /z2 switch that is unrecognized and try to convert from OMF to COFF when used as ml file.asm?

Lastly I understand that Irvine32.lib Kernel32.lib User32.lib are libraries for the program but don't understand why or what the /SUBSYSTEM:CONSOLE switch is/does.

I know this is an overload but I would appreciate any information on the following questions. Thank you.

dedndave

Win32 uses COFF object modules and PE exe's
16-bit DOS used the OMF object format and MZ exe's
there were a couple others, like NE for windows 3.1, etc
if you want to build MZ exe's you still can, by using a 16-bit linker

the /z2 switch is probably a linker switch that applies to OMF/MZ files
when we use ML to create COFF files, we typically use the /c switch also
this tells ML not to link

without /c, it is probably set up to build MZ exe's as the default
i think you have to do it as 2 steps for COFF files

/SUBSYSTEM:CONSOLE tells the linker to set a bit in the exe header
when the OS loads a PE exe, it uses this bit to see if a console window should be allocated

/SUBSYSTEM:WINDOWS - no console window allocated
for many programs (GUI apps, or those using MessageBox only), no console is needed

we can call AllocConsole if we want a console window
that's all the OS does if the console bit is set   :P

for most of the programs you are likely to build for class, i think /SUBSYSTEM:CONSOLE is what you want