How to install MASM32 on Windows 10

In this guide you will learn how to install MASM32 on a Windows 10 machine, and also how to modify the Path environment variable to use the MASM tools directly from the command prompt. By the end of the guide you will have an environment to start writing software in assembly.

Let’s begin.

Download MASM for Windows 10

The first thing you need to do is head over to the MASM32 SDK download page. Select a mirror and your download should begin.

Next open up the archive and extract the installer to your desktop.

Installing MASM on Windows 10

Double click on the installer. It will ask for administrator privileges. This application is deemed to be safe so you can safely press yes. After you have granted permissions you will see a dialog similar to the one below:

Click on the install icon on the top left and select the drive you want to use to install MASM. I will select my D:\ partition. MASM will install all the necessary files to the root directory of whatever partition you select.

Tip: I like to create a separate partition for my assembly projects and install MASM to the root directory of the partition. This makes it much easier to include libraries and includes such as windows.inc and friends.

MASM will proceed to run a bunch of tests to see if you’re computer is compatible and able to run MASM32. You will see a number of dialog boxes appear that require you to press the ok button.

Once the tests are complete press the extract button.

After the extraction has completed you will see another dialog box that informs you a command prompt will appear to complete the installation. Press ok and let the installation finish. It should only take a few moments.

After the installation has finished you will once again see a couple of dialog boxes that require you to press ok. You will also see a different type of dialog box similar to the one below. This runs a VB script to add an icon to your desktop for the MASM editor. If you want an icon on your desktop press yes.

Finally if everything went well you will see the final dialog box telling you the installation is complete.

Don’t run off just yet

I don’t use the default MASM editor. Instead I use Vim, or Sublime. This means I need to call the MASM compiler and linker directly from the command line to build my code. To do this you need to add the location of the MASM32 installation directory to your Path environment variable.

Adding a directory to environment variable Path on Windows 10

Open up the system properties dialog by entering the following command on the command prompt:

sysdm.cpl SystemProperties

Click the advanced tab, and click the Environment Variables button.

Next select the Path item from the list and click Edit.

On the next dialog press New and enter the path to the MASM bin directory. This contains the tools needed to compile and link assembly. For me the path is D:\masm32\bin. In most cases just change the drive letter if you installed to a different partition. The rest of the path is the same.

Press the ok button, and then then the apply button to save and close the system properties dialog.

Open a new command prompt and enter the following command to run the MASM assembler:

ml 

If everything installed correctly and your Path is setup correctly you will see some output similar to the image below:


💡 Assembly Language Weekly Newsletter

Every week I publish a newsletter that contains tutorials, tips, tricks and resources related to assembly language. If you would like to receive this newsletter subscribe here: http://eepurl.com/ghximb

All Done!

And that’s all there is to it folks. If you want to hit the ground running check out my guide on how to compile and link MASM assembly to produce an executable on Windows 10.

If you’re having any issues following this guide please leave a comment and I will help you the best I can. You can also check out the official documentation includes detailed installation instructions and FAQ’s to solve common problems.

Is Assembly Language Difficult?

Is Assembly Language Difficult?

In this article I want to discuss a popular question that I get asked: Is assembly language difficult to learn? The short answer is no, but there’s a little more to it than that.

Assembly language by itself is just a set of mnemonics. A way for programmers to write software that can directly interface with the CPU, memory, IO and hardware. Without it programmers would have to write programs in machine language.

What is machine language?

A processor is the brain of the computer. It performs billions of operations per second without breaking into a sweat. Embedded in the processor are instructions. These instructions tell the processor what to do and are defined by the processor manufacturer. If you’re really interested in this stuff you can read the Intel manuals.

As an example when you perform a mov instruction in assembly this is converted to the binary instruction for the given processor.

Programming this way is very possible, but also painful … and a complete waste of time. This is why assembly language was invented. Assembly language has a direct 1:1 relationship with machine instructions with some macros, and helpers etc. sprinkled on top to make life easier.

But, is it difficult to learn?

While the assembly language itself isn’t difficult to learn, becoming proficient with assembly is. An assembly programmer must understand how a computer works under the hood. If you’ve only ever used high level languages (HLL’s) you may not understand the basics such as how the CPU works, how memory is addressed and managed, or how to read and write to IO.

For many programmers wanting to learn assembly there’s is often a wide knowledge gap that needs bridging before you can start being productive. This takes time. It took me 10 years and a BSc in Computer Science to finally grasp assembly and computer architecture. I’m a slow learner who never really had any interest in assembly until I had a use case that required it. Kids today are much faster than my old brain.

Learning to program in assembly is completely different to programming in other languages. If you already know a language you will have to mentally shift the way you think about programming to learn and understand assembly. If you don’t know a language it would probably help to learn C before attempting assembly to get a higher level view of how to write software before diving down the rabbit hole.

With enough time and practice anybody can learn to become a good assembly programmer.

Is assembly language useless?

One of the biggest misconceptions I hear is that assembly language is useless. Some will claim it is only useful for things like optimization or game development. Others will claim writing software in assembly takes exponentially longer than in HLL’s. This is not true and can definitely have an impact on whether a person decides to learn assembly or not.

I generally find those that spout such nonsense don’t have enough experience with the language to do anything practical. And that’s fine, but those people should not speak in discussions they have no knowledge in.

I write assembly for ARM microcontrollers on a regular basis. I also write exploits and proof of concepts using assembly. Assembly language is not brainfuck. It is not an esoteric language who’s purpose is purely for programmer gratification and brownie points.

It’s a very useful language that gives you complete freedom and control over a machine within the limitations of the system. For example you can’t run in 16-bit real mode within modern versions of Windows so you still have some restrictions (excluding hackers, or booting into DOS).


💡 Assembly Language Weekly Newsletter

Every week I publish a newsletter that contains tutorials, tips, tricks and resources related to assembly language. If you would like to receive this newsletter subscribe here: http://eepurl.com/ghximb

TLDR;

Assembly language is difficult to learn because it requires a deeper understanding of system architecture at the most fundamental level. Once you understand this and bridge the knowledge gap you will find learning and programming in assembly is easy and fun.

If you would like me to expand further on anything in this article, or you have any questions, feel free to leave a comment.

How to compile and link MASM32

In this guide you will learn how to compile a MASM assembly file into a Windows executable.

Prerequisites

Before we begin you’re going to need to install MASM32. I’ve written a guide on how to do that. MASM includes the required compiler ml.exe and the linker link.exe. The documentation for each are below.

Once you have MASM installed copy the sample code below and save it as program.asm:

.386
.model flat,stdcall
.stack 4096
.code
main PROC
nop
main ENDP
END main

Our executable will do absolutely nothing. It will be used to test compilation and linking. Let’s do that …

The Not So Easy Way

Some time in the past it was possible to run ml.exe and have it produce an executable. This method has never worked for me for reasons I will discuss in a moment:

ml.exe program.asm 

On my system this produces the following error:

LINK : warning LNK4044: unrecognized option "z2"; ignored

This error occurs because the compiler attempts to compile and link, but if your ml.exe and link.exe versions do not match you will run into this same problem.

The reason is because ml.exe is attempting to pass the /z2 option to link.exe, but the linker doesn’t recognize the option. This is discussed in a bit more detail here.

Fear not my friends, there is a solution!

The Other Way

Instead of expecting ml.exe to call link.exe you can instead compile the assembly into .obj file and call link.exe yourself. An equally simple solution.

You do that like so:

ml.exe /c /coff program.asm
link.exe /subsystem:windows program.obj

The first line compiles the MASM assembly file into an COFF (common object file format) file. The /c option tells ml.exe to not run link.exe. The /coff option is what tells the compiler to generates a COFF file.

The second line runs the linker. The /subsystem:windows option is required and tells the operating system how to run the executable.

Running the 2 commands will compile and link your MASM assembly to produce a Win32 executable. Note the above will not work if you’re using MASM64.

If you have any problems or questions please leave a comment below.


💡 Assembly Language Weekly Newsletter

Every week I publish a newsletter that contains tutorials, tips, tricks and resources related to assembly language. If you would like to receive this newsletter subscribe here: http://eepurl.com/ghximb