The MASM Forum

General => The Campus => Topic started by: Pokerice on May 10, 2014, 06:34:49 PM

Title: help with masm
Post by: Pokerice on May 10, 2014, 06:34:49 PM
Hello, I am trying to learn assembly with masm32 but I am confused about a few things.

1) I tried opening the demo 1 and 2 but it seemed to do nothing or it exited before I can take a look at it.

2) I cannot find the ml.exe or linker.exe in the folder(I was trying to use the ml command in cmd but it is unrecognized).

3) I read that one of the advantages of assembly is its small size, but looking at demo 1 (hello world), the asm file is 2KB while exe is 3KB. Is this considered to be small?

4) I am currently trying to follow the "Iczelion's tutorial" on assembly, are there any other good tutorials/readings? (Not sure if Iczelion's tutorial is outdated or not)
Title: Re: help with masm
Post by: jj2007 on May 10, 2014, 06:44:58 PM
First things first: Welcome to the Forum :icon14:

Please try to be a bit more precise. There is no file or folder "demo" in \Masm32\examples
Below a simple example:

include \masm32\include\masm32rt.inc

.code
AppName   db "Masm32:", 0

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

end start


You can use print "hello world" instead of the MsgBox. If the console window closes too fast, use inkey "hit a key" before exit.

Iczelion's tutorials are still the best way to learn Windows programming. See also Tips, Tricks & Traps (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm) for a concise introduction and some helpful material.
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 06:53:01 PM
Thanks!

The demo is in \Masm32\tutorial\console\...
I just tried adding the inkey just before exit in demo1. When I opened the exe or go Project>Run program, nothing happens.
Title: Re: help with masm
Post by: dedndave on May 10, 2014, 08:12:21 PM
Iczelion's tutorial is a bit out of date
however, it is still a great tutorial, with a little rework

one example is that the masm32 libraries and include files have been vastly updated since it was written
Iczelion might show you how to PROTOtype windows API functions that are now already done for you
it might also tell you to define some windows constants and structures that are already defined in windows.inc
Title: Re: help with masm
Post by: dedndave on May 10, 2014, 08:15:49 PM
ML and LINK are in \masm32\bin
it's not a requirement, but i like to add that folder to my PATH

3 Kb is fairly small, in terms of PE executables
it's not as small as some old DOS .COM programs
but, compared to a compiler EXE, it can be very small
some compilers might make a 60 Kb EXE for Hello World - lol
Title: Re: help with masm
Post by: dedndave on May 10, 2014, 08:19:40 PM
as for the examples, try the ones in \masm32\examples, rather than the ones in \masm32\tutorial
however, that should produce an output

both demo1 and demo2 produce output for me
you may have to open a console window in the folder, then type the EXE name to execute
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 08:29:32 PM
Thank you dedndave, indeed the ML and LINK is in the bin folder.

Regarding to the size, its just that I heard people can get below 20bytes for a simple hello world program with assembly. The demos still doesn't work though even with console but I guess I will just skip them and go to examples, thanks again :biggrin:
Title: Re: help with masm
Post by: dedndave on May 10, 2014, 08:32:17 PM
20 bytes is an old DOS 16-bit .COM program
and, yah, they can be really Tiny   :P

but, nowdays, everyone has terabyte drives and gigabytes of RAM
small isn't as big a deal as it used to be
i still try to keep an eye on size - out of habit, mostly
Title: Re: help with masm
Post by: Vortex on May 10, 2014, 08:47:08 PM
Hi Pokerice,

Welcome to the forum.

Dave is right. Those very short applications are 16-bit DOS COM. Here is an example :

.model tiny

.data

string db 'Hello!$'

.code

org 100h

start:

    mov     dx,OFFSET string

    mov     ah,9
    int     21h

    mov     ax,4C00h
    int     21h

END start
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 09:07:08 PM
Thanks Vortex 8)

I can't seem to open the exe (incompatible version) and I get symbol not defined :DGROUP if I try to assemble and link in the editor.
Title: Re: help with masm
Post by: hutch-- on May 10, 2014, 09:18:41 PM
If you are going to build 16 bit COM files you need to use the old OMF linker and write your own batch file to build it, the normal linker in MASM32 is only for 32 bit PE files.
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 09:35:00 PM
No wonder it wouldn't work, thanks hutch--. Guess I will concentrate on 32bit for the time being.
Title: Re: help with masm
Post by: Vortex on May 10, 2014, 09:41:30 PM
Hi Pokerice,

You can check Build.bat in the attachment. link16.exe is the 16-bit linker :

\masm32\bin\ml /c /AT Hello.asm
\masm32\bin\link16 /TINY Hello.obj,Hello.com;
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 10:02:29 PM
I ran your Build.bat, it created the obj and com files. But when I open the .COM, it is still incompatible.
Title: Re: help with masm
Post by: Vortex on May 10, 2014, 10:06:55 PM
Hi Pokerice,

What's your operating system? The 64-bit versions of Vista,Win 7 and Win8 will not allow 16-bit DOS applications :

http://msdn.microsoft.com/en-us/library/bb756962.aspx
Title: Re: help with masm
Post by: Pokerice on May 10, 2014, 10:13:12 PM
Awww, I am indeed using windows 7 x64 :(
Title: Re: help with masm
Post by: Gunther on May 10, 2014, 11:42:09 PM
Hi Pokerice,

Quote from: Pokerice on May 10, 2014, 10:13:12 PM
Awww, I am indeed using windows 7 x64 :(

that's tricky. The only chance is to install a Virtual Machine. You can check that thread (http://masm32.com/board/index.php?topic=2150.0) for details.

Gunther
Title: Re: help with masm
Post by: Pokerice on May 11, 2014, 12:30:37 AM
Thanks Gunther, I will remember this for future use.

I also found out the problem with the demos. I wasn't doing the "console assemble and link", thus no output was shown. :lol:

*EDIT: All of a sudden, when assembling & linking, I am getting this extra file name.err. Is this an error file? (Although it runs fine)
Title: Re: help with masm
Post by: dedndave on May 11, 2014, 03:32:03 AM
as i recall, the batch files Hutch wrote (\masm32\bin folder)
redirect the error output of ML and LINK into a text file, then display that
it may be the file you are seeing

also, since about version 6, ML has a "helper" file with the .err extension
it is filled with error message text
Title: Re: help with masm
Post by: Vortex on May 11, 2014, 06:47:01 AM
Hi Pokerice,

If you are using Windows 7 x64 Pro, you can install Windows XP Mode.
Title: Re: help with masm
Post by: Pokerice on May 11, 2014, 02:59:36 PM
I see, so how do I open the err file?

Unfortunately, I am using ultimate, thanks though vortex.
Title: Re: help with masm
Post by: dedndave on May 11, 2014, 03:02:52 PM
you can always use a program like HxD to view files

http://mh-nexus.de/en/hxd/ (http://mh-nexus.de/en/hxd/)

it might be a plain text file, though - in which case, you can open it with NotePad
of course, you can open any file with NotePad, it may look like garbage
but, you might get some idea of what's in it
Title: Re: help with masm
Post by: Pokerice on May 11, 2014, 06:17:30 PM
Thanks dedndave!

This might be outside of masm but is there any other way to to run/link the COM file format in windows 7 x64 Ultimate?
Title: Re: help with masm
Post by: Vortex on May 11, 2014, 06:34:14 PM
Hi Pokerice,

QuoteThis might be outside of masm but is there any other way to to run/link the COM file format in windows 7 x64 Ultimate?

The only solution is to use a virtual operating system or DOSBox.
Title: Re: help with masm
Post by: Pokerice on May 11, 2014, 07:04:09 PM
Alright, guess there is no other choice than to download windows xp mode and virtual pc.
Title: Re: help with masm
Post by: Gunther on May 11, 2014, 07:19:29 PM
Pokerice,

Quote from: Pokerice on May 11, 2014, 07:04:09 PM
Alright, guess there is no other choice than to download windows xp mode and virtual pc.

Windows XP mode isn't bad. DosBox is a good alternative, because you can run some DOS applications in full screen mode. That's not possible with XP mode.

Gunther