Table of Contents

Writing assembly

In the Wonderful toolchain, assembly files use the .s extension. They are compiled using the GNU assembler and the C preprocessor.

Creating an assembly file

It is recommended to start with a preamble similar to the following:

#include <wonderful.h> // (1)!
#include <ws.h> // (2)!

    .code16 // (3)!
    .arch i186 // (4)!
    .intel_syntax noprefix // (5)!

  1. Include the Wonderful toolchain's basic definitions. This provides some useful assembly defines and macros.
  2. Include the libws library's definitions. This library supports being included in an assembler, and provides hardware-related defines - such as I/O port names and masks.
  3. Tell the assembler to emit 16-bit code; this is useful as the GNU assembler supports all kinds of x86 code, including 32-bit and 64-bit.
  4. Tell the assembler to emit 80186 code; this unlocks some additional 80186-exclusive opcodes supported on the NEC V30MZ.
  5. Tell the assembler to emit Intel-syntax assembly; this is entirely optional, but the examples for external assembly files in this guide all make use of the Intel syntax, as opposed to the default AT&T syntax used in inline assembly.

Note that to export a symbol (make it visible outside of the specific file, or translation unit), you need to use .global, like so:

.global strlen
strlen:

Useful macros

wonderful.h provides some useful macros: