MASM

Back to: | Home   |   TOC Gray Pages   |   Bottom   |  

The Microsoft Macro Assembler (abbreviated MASM) is an assembler for the x86 family of microprocessors. It was originally produced by Microsoft for development work on their MS-DOS operating system, and was for some time the most popular assembler available for that operating system. It supported a wide variety of macro facilities and structured programming idioms, including high-level constructions for looping, procedure calls and alternation (therefore, MASM is an example of a high-level assembler). Later versions added the capability of producing programs for the Windows operating systems that were released to follow on from MS-DOS. MASM is one of the few Microsoft development tools (another was NMAKE) for which one version targets both 16-bit and 32-bit. Early version were MS-DOS applications. Later versions also were OS/2 applications (versions 5.1 and 6.0) and later versions after that (versions 6.1+) were Win32 console applications (initially (in versions 6.1 and 6.11) with the Phar Lap TNT DOS extender included to run these versions on MS-DOS). However see Phar Lap (company) for the whole debacle that cause early versions that were Win32 console applications (version 6.1) to fail to run on final versions of Windows NT.

MASM32 assumes that the programmers who will use it already have experience in 32 bit Windows API programming using compilers and have done some work in assembler. It is not designed as a beginners package and it does not have the support for beginners to learn the basic concepts about assembler. It is recommended that beginners to programming learns a compiler like C/C++ Pascal/Delphi or PowerBASIC before they start on an assembler as this will produce the necessary experience to deal with concepts like registers, data sizes or registers, data types, assembler mnemonics, system API calls and different calling conventions. The learner can always come back to assembler once they are familiar and confortable with a compiler.Top

Another very good alternative is to check out the website run by Randy Hyde who is the author of the classic Art Of Assembler and its successor HLA (High Level Assembler). Randy Hyde is an enormously experienced programmer, teacher and author and he has an excellent track record in making assembler accessible to a wide number of people.

Studiemateriaal

One problem with most of the books out there is that they teach assembly language programming under MS-DOS. 10 or 15 years ago, learning assembly language under MS-DOS was a good idea. Today, however, MS-DOS is totally obsolete. Any time you spend learning MS-DOS programming is a complete waste of time. Once you subtract away all the MS-DOS-based books for MASM, there are only a couple of tutorial books available, and most of those teach advanced Win32 programming, not beginning assembly language programming. Therefore, as is the case with most other endeavors in life, it's not the quantity of tutorials available out there, but the quality.

HLA is blessed with the 32-bit edition of "The Art of Assembly Language Programming" (both in electronic and published form) that teaches beginning assembly language programming under Windows or Linux. As HLA does not run under DOS, no DOS tutorial is available.

Most of the technical articles out there describe how to use a given assembler to make system calls to a specific operating system. For example, the excellent tutorials by Iczelion are a set of over 30 technical articles with MASM32 source code describing how to write Windows GUI applications. These tutorials are so popular that many of them have been translated from MASM32 to other assemblers (e.g., NASM, SpAsm/RosAsm, and HLA). There are similar papers available describing Linux system calls with assemblers such as NASM, Gas, and HLA.

By far, the largest set of papers on assembly language programming center around the use of DOS. This is unfortunate, as DOS is quite obsolete at this point and spending one's time learning DOS programming techniques is probably a waste of your time. One thing that is good about such articles, however, is that many of them describe how to program the underlying hardware on (older) PCs. Unfortunately, as newer PCs drift away from the original PC design (e.g., relying on Plug and Play and features like USB and Firewire), the applicability of these articles is diminishing.Top


Typical applications

Hard-coded assembly language is typically used in a system's boot ROM (BIOS on IBM-compatible PC systems). This low-level code is used, among other things, to initialize and test the system hardware prior to booting the OS, and is stored in ROM. Once a certain level of hardware initialization has taken place, execution transfers to other code, typically written in higher level languages; but the code running immediately after power is applied is usually written in assembly language. The same is true of most boot loaders.

Many compilers render high-level languages into assembly first before fully compiling, allowing the assembly code to be viewed for debugging and optimization purposes. Relatively low-level languages, such as C, often provide special syntax to embed assembly language directly in the source code. Programs using such facilities, such as the Linux kernel, can then construct abstractions utilizing different assembly language on each hardware platform. The system's portable code can then utilize these processor-specific components through a uniform interface.

Assembly language is also valuable in reverse engineering, since many programs are distributed only in machine code form, and machine code is usually easy to translate into assembly language and carefully examine in this form, but very difficult to translate into a higher-level language. Tools such as the Interactive Disassembler make extensive use of disassembly for such a purpose.

A particular niche that makes use of the assembly language is the demoscene. Certain competitions require the contestants to restrict their creations to a very small size(e.g. 1kb, 4kbs, 64kbs), and assembly language becomes the language of choice to achieve this aim. Top


Resources on the Internet
Author’s page http://www.drpaulcarter.com/
NASM SourceForge page http://sourceforge.net/projects/nasm/
DJGPP http://www.delorie.com/djgpp
Linux Assembly http://www.linuxassembly.org/
The Art of Assembly http://webster.cs.ucr.edu/
USENET comp.lang.asm.x86
Intel documentation
http://developer.intel.com/design/Pentium4/documentation.htm