Skip to content

CS 271

This class uses MASM (the Microsoft Assembler) and Visual Studio for assembling and running code. If you do not want to install a Windows VM and Visual Studio, MASM does work under Wine with some tweaks.

Note: Debugging assembly in Wine may prove much harder than in Visual Studio! winedbg may work, but there is no editor integration.

Note 2: This version of MASM may not support some things that are required by some versions of this class (like 64-bit mode). At time of writing (Winter '21), this class does not require anything extra, but YMMV.

Steps mostly taken from this guide by Ryan Eberhardt and sources from the Irvine textbook Github mirror.

1. Choose a Wine prefix:

mkdir -p ~/.local/share/wineprefixes/masm/
alias wine_masm="WINEARCH=win32 WINEPREFIX=~/.local/share/wineprefixes/masm/ wine"

2. Install MASM:

wget https://masm32.masmcode.com/masm32/masm32v11r.zip
unzip masm32v11r.zip
wine_masm install.exe

3. Install the Irvine support materials:

wget https://github.com/surferkip/asmbook/raw/main/Irvine.zip
unzip Irvine.zip
mv ./Irvine ~/.local/share/wineprefixes/masm/drive_c/Irvine

4. Set PATH, LIB, and INCLUDE in the Registry:

These will add the MASM and Irvine library headers to the system path so INCLUDE directives do not need to specify the full path.

wine_masm regedit

Create the following String Values:

Key Value
HKEY_CURRENT_USER/Environment/PATH %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\masm32\bin
HKEY_CURRENT_USER/Environment/INCLUDE C:\masm32\include;C:\Irvine
HKEY_CURRENT_USER/Environment/LIB C:\masm32\lib;C:\Irvine

5. Grab the example project:

wget https://github.com/surferkip/asmbook/raw/main/Project32_VS2019.zip
unzip Project32_VS2019.zip

6. Set up the wrapper script:

Put this script somewhere in $PATH, e.g. at ~/.local/bin/masm

#!/bin/bash
set -e # Stop on errors
shopt -s expand_aliases

# Get the path to the file without a .asm extension
FILENAME="$(basename "$1")"
EXTENSION="${FILENAME##*.}"

shopt -s nocasematch # String case-insensitive comparison
if [[ "$EXTENSION" = "asm" ]]; then
   FILENAME="${FILENAME%.*}" # Remove extension
fi
FILEPATH="$(dirname "$1")/$FILENAME"

# WINEDEBUG flag hides the fixme:ntdll:NtQuerySystemInformation warning (which can be safely ignored)
alias wine_masm="WINEDEBUG=fixme-all WINEARCH=win32 WINEPREFIX=~/.local/share/wineprefixes/masm/ wine"

echo "> Assembling..."
wine_masm ml -nologo -c -coff -Zi "$FILEPATH.asm"

echo "> Linking..."
wine_masm link -nologo -subsystem:console irvine32.lib kernel32.lib user32.lib "$FILEPATH.obj"

echo "> Running..."
echo
wine_masm "$FILEPATH.exe"

7. Test it out:

cd path/to/Project32_VS2019
masm AddSub2.asm