How to Assemble Your First Program Using JWasm

Written by

in

JWasm is a free, fast, open-source, and highly portable macro assembler that translates x86 assembly language into machine code. Originally created as a fork of the Open Watcom WASM assembler, JWasm stands out because it is designed to be drop-in compatible with Microsoft’s MASM (Macro Assembler) syntax while offering cross-platform support without artificial licensing restrictions.

A complete beginner’s guide to setting up, understanding, and executing code with JWasm involves the following essential steps: 1. Key Features: Why Use JWasm?

Before diving in, it helps to understand why developers choose JWasm over other options:

MASM Compatibility: It fully supports MASM v6 features, including complex macros, high-level directives like .IF, .WHILE, and advanced function handling with PROTO and INVOKE.

Multi-Architecture Support: It seamlessly generates 16-bit real mode, 32-bit protected mode, and 64-bit long mode code.

Versatile Output Formats: Unlike traditional MASM, JWasm can natively export binaries in Intel OMF, MS COFF (⁄64-bit), ELF (⁄64-bit), raw binary (.bin), and DOS MZ executable formats.

Cross-Platform: The toolchain is written in portable C, meaning you can run the assembler natively on Windows, Linux, DOS, or OS/2. 2. Setting Up Your Environment

To get started, you will need the assembler, a linker, and a text editor.

Download the Assembler: Head to the JWasm GitHub Project Page or its official SourceForge Distribution to grab the precompiled binary file (e.g., jwasm.exe for Windows or jwasm for Linux).

Get a Linker: Assemblers only create object files (.obj or .o). You need a linker to turn them into executables. A highly compatible companion tool is JWlink, a modified Open Watcom linker.

Choose an Editor: Any text editor works. Popular setups include Visual Studio Code, Notepad++, or Vim.

Environment Variables: For ease of use, add the directory containing jwasm and your linker to your system’s PATH environment variable. 3. Writing Your First Code (Hello, World!)

JWasm shines when using MASM’s simplified high-level notations. Create a text file named hello.asm and input the following standard 32-bit Windows console application structure:

.386 .model flat, stdcall option casemap:none ; Include Windows API definitions (standard MASM syntax) include \masm32\include\kernel32.inc includelib \masm32\lib\kernel32.lib .data hello_msg db “Hello, JWasm World!”, 13, 10, 0 .code start: ; Use the INVOKE notation supported by JWasm for easier API calls invoke GetStdHandle, -11 ; -11 is STD_OUTPUT_HANDLE mov ecx, eax ; Move file handle to ecx invoke WriteFile, ecx, addr hello_msg, 21, addr [esp], 0 invoke ExitProcess, 0 end start Use code with caution.

Note: The INVOKE macro automatically maps out the system push and call structures behind the scenes while checking for data types. 4. Compiling and Linking Your Program

Once your file is saved, open your terminal or command prompt, navigate to the folder containing your code, and run the following commands: Step 1: Assemble the file into a COFF Object format jwasm -coff hello.asm Use code with caution. JWasm – OSDev Wiki

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts