News:

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

Main Menu

Help! Couldn'g get Started with masm even after 2 days!

Started by amrak, March 12, 2015, 10:43:31 PM

Previous topic - Next topic

amrak

Hi All,
Been two days since I tried to kick start learning masm, but, still I am unable to assemble in masm. This is how I started the process a week ago, I studied "Art of Assembly" by Randall Hyde to get the basics of CPU architecture registers, interrupts, addressing modes etc, indeed it was a very good book. Then I moved on to the practical aspect, I got directed to masm since Art of Assembly uses masm as the assembler, but "Art of assembly" which I referred to was for 16 bit 8086 cpu. I was recommended by a member in my earlier post to give up on 16 bit and move on with 32 bit versions. I got a copy of "Art of Assembly 32 bit version" the problem is it is using some HLA programs which is not really my intention to learn. I got another book by Kip. Irvine "Assembly language for x86 processors" I was following the book but the book practicals need Microsoft visual studio 2012, I tried to download it as well but it is taking about 11 hours to complete the download.  Are there no simple programs that can assembl masm source, I have installed masm32, do we need visual studio 2012 or some HLA or something else always to learn masm! I have gone through lots of articles by authors on the web, almost all of their tutorials need some other tools other than masm32! Are there processes where you dont need such tools and learn masm. Please help me proceed. Being a newbie is tough in this world, guess those who has the knowledge makes it even more tougher by including so many things which may or may not be relevant for a new user.

dedndave

unfortunately, there is no book that is specifically designed for use with the masm32 package (that i'm aware of)
and, still, the masm32 package is probably the easiest way to get started with win32 assembly language

there are a few tutorials
the masm32 package also comes with help files and many example programs

there are some basics that the books can help you with
data types, registers, assembler syntax - basic things that are needed to start at the ground level

however, when it somes to specific code, the book examples won't coincide with the real world of masm32

MtheK

  All I've ever used is NOTEPAD to edit my .asm file, and a simple .bat
(asmlnk32.bat) to assemble and link (plus a few extra tools to make
reports on it). Nothing else needed (at least for me). I've done this
since 16bit in MASM611.

MtheK

  Snippets from my .bat:



@ECHO OFF

rem  set WDIR, then RUN FROM \DAD\MASM3211 (drive-independent)

IF [%1]==[]   GOTO PARMREQ
GOTO NOTSLOW
:PARMREQ
echo missing program name
GOTO EXIT
:NOTSLOW

rem ########### ASSEMBLY ###########   (SXREF N/A!!)
\DAD\MASM3211\MASM32\BIN\ml /c /W2 /WX /I\DAD\MASM3211\MASM32\INCLUDE /Zi /coff /Sn /Fl%1.lst.txt /Fo%1.obj %1.ASM
set ASMLNK32ASMrc=%errorlevel%

IF ERRORLEVEL 1 GOTO BADA
IF ERRORLEVEL 0 GOTO GOODA
:BADA
echo  %~n0 %~d0 %errorlevel% ASM
GOTO EXIT
:GOODA

del %1.pdb

rem ########### LINK ###########
\DAD\MASM3211\MASM32\BIN\LINK %1.obj \dad\masm3211\masm32\lib\user32.lib \dad\masm3211\masm32\lib\kernel32.lib \dad\masm3211\masm32\lib\advapi32.lib \dad\masm3211\masm32\lib\winmm.lib /out:%1.exe /map:%1.map.txt /pdb:%1.pdb /SUBSYSTEM:CONSOLE /OPT:WIN98 /INCREMENTAL:NO /MAPINFO:LINES /MAPINFO:EXPORTS /DEBUG
set ASMLNK32LNKrc=%errorlevel%
IF %ASMLNK32LNKrc% GEQ 1 GOTO BADL
IF %ASMLNK32LNKrc% EQU 0 GOTO GOODL
:BADL
echo  %~n0 %~d0 %ASMLNK32LNKrc% LINK
GOTO EXIT
:GOODL

:EXIT


amrak

Thank you @dendndave and @methk for your reply. @methk, your suggestion is exactly the one that I was looking for. I will give it a try. Where do I place the asmlink32.bat in my system, should it be in the c:\masm32\bin or some place and is there anything I need to edit.

dedndave

it's helpful if the batch file is somewhere in the PATH environment variable
most computers have C:\Windows\System32 in the PATH
personally, i prefer to modify the PATH, and add the C:\masm32\bin folder to it
but, that is not a requirement
you can open a command window and type PATH or SET to see what the PATH variable is

i notice that his batch file has a folder named "DAD"
you might want to remove that part from all the command lines   :t

dedndave

a few things to note....

the masm32 package is designed to be installed in the root folder of the drive where you want your projects to be
for me, that is the C: drive, so mine is installed in C:\masm32
i don't try to assemble files that are on any other drive   :P

it makes things a lot easier if you follow that rule, although there are work-arounds

MtheK

  Those are all good ideas. For me, I place the .bat in the \MASM3211 folder.
In a DOS prompt, I do a 'cd' to that DIR, then just type:

asmlnk32.bat SAMPLE

  Be aware that this only works for my stuff. For other things,
u may have to adjust the .bat to point to them in the ML line.

amrak

Thank you @Mthek and @Dedndave. Things became much more clearer. :t

jj2007

1. Open \Masm32\qeditor.exe
2. Paste this snippet:
include \masm32\include\masm32rt.inc

.code
AppName db "Masm32:", 0

start: MsgBox 0, "Hello World", addr AppName, MB_OK
exit

end start


3. Save as \Masm32\MyTest.asm
4. Go to menu Project/Build all
5. Go to menu Project/Run Program
6. Send a letter to Bill Gates telling him where he can shove VS.

Vortex


hutch--

The problem is that you cannot mix different systems. If you have installed MASM32 successfully, all you need to add to have all you need to start is the old WIN32.HLP file and the Intel manuals for complete reference to the instructions. It is also worth getting familiar with MSDN to get later API functions which you will need further down the track. Have a look through the tutorials in MASM32 to get the very basics then you can start working on the example code which has a range of more advanced examples.

rrr314159

Hi amrak,

Welcome to the Masm Forum.

These guys are giving 2 much advice! They're all correct of course. I use a variation of MtheK's batch file approach myself, find it gives me more control; altho I think qeditor better than notepad (to each his own). But I think jj2007's advice is best because it's simplest. I'd like to mention a slight improvement on it, tho.

You may be up and running already - I hope - still this might be worth reading.

I assume you're familiar with basic Windows use. Now, the only problem with jj's advice is, you don't want to put your Test.asm file in masm32 directory, it will make a mess.

First, create a new folder anywhere convenient, like on your desktop; call it "Masm stuff" or similar.

In it, create a new text file (right click, select new, etc) rename that file to "test.asm". Of course it will ask "are you sure", tell it yes (I hope you know how to do this). Double-click on test.asm and it will automatically open with qeditor (assuming you've installed masm32 right).

NOW, follow the rest of jj2007's advice: cut and paste his code into the window, save it (CTRL-s or use the file menu), build it, run it, send letter to Bill Gates. But make sure you sign the letter "jj2007", or you might get in trouble!

This way all the files will be in that directory, not messing up the masm32 directory. If this directory gets full of examples as you progress, just make another one and fill that with new stuff.

If u want to use batch files (after a while, menu commands aren't powerful enuff) hit CTRL-D to get a command window. Very convenient, compared to navigating there as MtheK does.

U don't need intel manuals for now, go to the help menu and select "opcodes", all the basics are there. Also u don't need to hassle with environment path - again, assuming masm32 is installed correctly. The menus have other useful stuff too. Go thru masm examples, as hutch mentions: copy the examples to your directory; this way u keep all your stuff in one place.

ask q's when you get stuck, good luck
I am NaN ;)

amrak

Thank you for the help everyone, appreciate it. Now I am able to use masm. Thank you all so much

MtheK

  FYI:  I found a bit better way for my .bat for LINK:



set ASMLNK32path=\dad\masm3211\masm32\lib\
set ASMLNK32incl=user32.lib advapi32.lib winmm.lib ntdll.lib
set LINK=/NOLOGO /VERBOSE /RELEASE /SUBSYSTEM:CONSOLE /OPT:WIN98 /INCREMENTAL:NO /MAPINFO:LINES /MAPINFO:EXPORTS /DEBUG
\DAD\MASM3211\MASM32\BIN\LINK %1.obj %ASMLNK32incl% /LIBPATH:%ASMLNK32path% /DEFAULTLIB:kernel32.lib /OUT:%1.exe /MAP:%1.map.txt /PDB:%1.pdb >%1.map.STDOUT.txt



At least there isn't repetition of the path any more. It's been
quite a while since I looked at this.

  To assemble/run any programs in this forum w/my .bat, since all the
includes start w/a backslash (unlike mine), in my case, I made
c:\masm32 an alias (junction) pointing to where I actually have it in
my DIRs.

  I then actually tried qeditor, opening that snippet file, then did
assemble & link, then run program, and it all worked OK. This looks
similar to PWB in 16bit. Some default writes a .txt to \bin?

  I tried getting LINK to "auto"-resolve references, but I can't seem
to get it to work. In the mainframes' "LINK", any un-resolved refs are
automatically found via concatenated "LIBPATH"s; I don't have to
specify any names manually.

  For the "libraries" (incl) files, basically, I have to code
everything that all my programs will use, tho only the actual refs
used in that program get loaded (per /VERBOSE).  I must also specify
the extension, else it defaults to '.obj' and doesn't find them.

  Can LINK even do that? I only have the 16bit manual explaining it,
which doesn't have /LIBPATH. Searching the Web didn't help.

  Is this because these names aren't equal? For example, if I set
ASMLNK32incl to  "null"  or  *.lib  and remove /DEFAULTLIB, I get this:

SAMPLE.obj : error LNK2001: unresolved external symbol _GetLastError@0

which is normally found in kernel32.lib(kernel32.dll).

  I guess there could be duplicate issues if the same name was in
more than one \lib file, so perhaps it didn't make sense to check every
file, and so it must be manually coded, and not generic? IE: they can't
resolve themselves a la the mainframe?

  I guess it actually took  *.lib  since I did NOT get this message:
LINK : fatal error LNK1181: cannot open input file "*.lib"
like I got when I set ASMLNK32incl to  nothing.lib  , but even so,
it still didn't resolve the ref.

  So it seems that a "library" is manually required if the program has
any external references? Is that why the MS WINAPI doc lists the
"library" name, so I can add it as a "library" to resolve all refs at
LINK time?

  Thankx...