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:

wine_masm install.exe

3. Install the Irvine support materials:

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:


6. Set up the wrapper script:

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

set -e # Stop on errors
shopt -s expand_aliases

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

shopt -s nocasematch # String case-insensitive comparison
if [[ "$EXTENSION" = "asm" ]]; then
   FILENAME="${FILENAME%.*}" # Remove extension
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..."
wine_masm "$FILEPATH.exe"

7. Test it out:

cd path/to/Project32_VS2019
masm AddSub2.asm