22. Running the assembler

The assembler is run from the command line, or from an IDE that interfaces with the assembler using the command line.

22.1. Basic invocation

The assembler is invoked in the following way:

$ as65816 [options] sourcefile [options]

As an example, to assemble a source file with debugging information and a list file, you can use:

$ as65816 --debug source.c -l

Command line options are optional arguments that tune the behavior of the assembler. They always start with a dash character. There are two variants, single letter options (-l to instruct the assembler to create a list file) starts with a single dash. The other variant is long descriptive options that starts with two dashes.

Some options require arguments. These follow the option, separated by a space or an equals sign (=). For single-argument options, the separator is optional:

$ as65816 -Iinclude source.c -D VERBOSE=2 --list-file=tiny-source.lst

In this case the -I option adds include as a directory to scan for header files. The symbol VERBOSE is defined in the preprocessor with value 2. A list file with a specific name is also produced.

The order in which the options appear normally do matter, except for the -I option that adds directories to search for header files. Such directories are searched in the order in which they appear on the command line.

To display the version of the assembler, use --version:

$ as65816 --version
Calypsi assembler for 65816 version 5.16

Command line options are described in Command line options.

22.2. Include search path

Header files are included by surrounding the filename with either double quotes or angled brackets:

#include "myheader.h"
#include <system.h>

Angled brackets are typically for system header files, while double quotes are for application-specific header files.

Note

The installation provides no system header files for the as65816 assembler. However, the preprocessor retains its standard behavior of supporting angled include files and searching the installation directory.

The search order for include files is as follows:

  1. Relative to compilation directory (double quote include only)

  2. In directories specified in the -I option in the order they appear on the command line

  3. The system directory, which is the Calypsi installation directory

Header files specified in angle brackets are not searched relative to the compilation directory. Otherwise, their behavior is identical.

Note

More precisely, the system header file directory is relative to the as65816 executable. If you move an installation, it will still find the correct system header file directory.

Note

No header files are currently provided with the assembler. The preprocessor search path exists for consistency with the C compiler.

22.3. Assembler output

The assembler outputs one or two files, an object file that can be linked with other object files and libraries by ln65816 to produce an executable file, and optionally a list file.

Object file

The object file is in ELF format, optionally including DWARF debugging information if --debug (or -g) is specified.

It contains:

  • A symbol table

  • Relocatable sections for code and data

  • Relocations, allowing linker to modify address values after section placement

  • DWARF-formatted source-level debugging information (if --debug was specified)

  • Vendor-specific data, including runtime attributes and additional the Calypsi C compiler tool chain-specific information not covered by ELF/DWARF, used by the linker and debugger, with section types 0x8000000a and 0x8000000b.

Note

DWARF version 5 is used. The implementation covers the needs of the Calypsi C compiler tool chain and includes vendor extensions.

Note

DWARF debug information from the assembler includes source line information. The object file also contains a symbol table.

List file

The list file is a text file meant to be shown with a fixed width font. It contains a header that shows assembler, version, time when it was created and the command line used. The assembly source is shown with corresponding hex machine code. It also shows macro expansions and includes a summary of code and data sizes.

The following example is the builtin source file from the C runtime library:

/****************************************************************************
 *
 * Copyright Håkan Thörngren
 *
 * This file is part of the Calypsi C library.
 * Permission to use with the Calypsi tool chain is hereby granted.
 *
 ****************************************************************************/

;;; ----------------------------------------------------------------------
;;;
;;; Builtin support.
;;;
;;; ----------------------------------------------------------------------

              .rtmodel version, "1"
              .rtmodel cpu, "*"

#include "macros.h"

              .extern _Dp

;;; ***************************************************************************
;;;
;;; _CLZ - count leading zeroes
;;;
;;; In: A - integer value
;;;
;;; Out: A - number of leading zeroes
;;;
;;; Uses: Y
;;;
;;; Result is undefined if A is 0.
;;;
;;; ***************************************************************************

              .public _CLZ
              .section libcode
_CLZ:         tay                   ; check for zero
              beq     30$
              ldy     ##-1
10$:          iny
              asl     a
              bcc     10$
20$:          tya
30$:          return

;;; ***************************************************************************
;;;
;;; _CLZL - count leading zeroes
;;;
;;; In: X:A - 32 bit integer value
;;;
;;; Out: A - number of leading zeroes
;;;
;;; Uses: X, Y
;;;
;;; Result is undefined if X:C is 0.
;;;
;;; ***************************************************************************

              .public _CLZL
              .section libcode
_CLZL:        txy                   ; upper part non-zero
              bne     10$
              tax                   ; lower part zero?
              beq     60$           ; yes, done
              ldy     ##15
              bra     30$
10$:          txa
              ldy     ##-1
30$:          iny
              asl     a
              bcc     30$
50$:          tya
60$:          return

Compiling with the -l option produces a list file:

###############################################################################
#                                                                             #
# Calypsi assembler for 65816                                    version 5.16 #
#                                                       14/Apr/2026  16:42:19 #
# Command line: builtin.s -l                                                  #
#                                                                             #
###############################################################################

0001                  /****************************************************************************
0002                   *
0003                   * Copyright Håkan Thörngren
0004                   *
0005                   * This file is part of the Calypsi C library.
0006                   * Permission to use with the Calypsi tool chain is hereby granted.
0007                   *
0008                   ****************************************************************************/
0009
0010                  ;;; ----------------------------------------------------------------------
0011                  ;;;
0012                  ;;; Builtin support.
0013                  ;;;
0014                  ;;; ----------------------------------------------------------------------
0015
0016                                .rtmodel version, "1"
0017                                .rtmodel cpu, "*"
0018
0019                  #include "macros.h"
0020
0021                                .extern _Dp
0022
0023                  ;;; ***************************************************************************
0024                  ;;;
0025                  ;;; _CLZ - count leading zeroes
0026                  ;;;
0027                  ;;; In: A - integer value
0028                  ;;;
0029                  ;;; Out: A - number of leading zeroes
0030                  ;;;
0031                  ;;; Uses: Y
0032                  ;;;
0033                  ;;; Result is undefined if A is 0.
0034                  ;;;
0035                  ;;; ***************************************************************************
0036
0037                                .public _CLZ
0038                                .section libcode
0039  000000 a8       _CLZ:         tay                   ; check for zero
0040  000001 f008                   beq     30$
0041  000003 a0ffff                 ldy     ##-1
0042  000006 c8       10$:          iny
0043  000007 0a                     asl     a
0044  000008 90fc                   bcc     10$
0045  00000a 98       20$:          tya
0046                  30$:          return
    \ 00000b 6b                   rtl
0047
0048                  ;;; ***************************************************************************
0049                  ;;;
0050                  ;;; _CLZL - count leading zeroes
0051                  ;;;
0052                  ;;; In: X:A - 32 bit integer value
0053                  ;;;
0054                  ;;; Out: A - number of leading zeroes
0055                  ;;;
0056                  ;;; Uses: X, Y
0057                  ;;;
0058                  ;;; Result is undefined if X:C is 0.
0059                  ;;;
0060                  ;;; ***************************************************************************
0061
0062                                .public _CLZL
0063                                .section libcode
0064  000000 9b       _CLZL:        txy                   ; upper part non-zero
0065  000001 d008                   bne     10$
0066  000003 aa                     tax                   ; lower part zero?
0067  000004 f00e                   beq     60$           ; yes, done
0068  000006 a00f00                 ldy     ##15
0069  000009 8004                   bra     30$
0070  00000b 8a       10$:          txa
0071  00000c a0ffff                 ldy     ##-1
0072  00000f c8       30$:          iny
0073  000010 0a                     asl     a
0074  000011 90fc                   bcc     30$
0075  000013 98       50$:          tya
0076                  60$:          return
    \ 000014 6b                   rtl

##########################
#                        #
# Memory sizes (decimal) #
#                        #
##########################

Executable  (Text): 33 bytes

22.4. Command line options

This section covers the as65816 command-line options in detail.

Options overview

Running the assembler from the command line without arguments results in a missing input file error, followed by a short help message:

$ as65816
Missing: FILE

Usage: as65816 [--version] [-o|--output-file OUTPUT-FILE] [-l]
               [--list-file LIST-FILE] [-I DIRECTORY] [-D IDENTIFIER]
               [-U IDENTIFIER] [-g|--debug] [--rtattr NAME=VALUE]
               [--weak-symbols] [--core CORE] [--target TARGET]
               [--code-model NAME] [--data-model NAME] FILE
  use 'as65816 --help' for detailed help

For more detailed help, use the --help option:

$ as65816 --help
Calypsi assembler for 65816 version 5.16

Usage: as65816 [--version] [-o|--output-file OUTPUT-FILE] [-l]
               [--list-file LIST-FILE] [-I DIRECTORY] [-D IDENTIFIER]
               [-U IDENTIFIER] [-g|--debug] [--rtattr NAME=VALUE]
               [--weak-symbols] [--core CORE] [--target TARGET]
               [--code-model NAME] [--data-model NAME] FILE
  use 'as65816 --help' for detailed help

Available options:
  --version                Display version number
  -o,--output-file OUTPUT-FILE
                           Name of output file
  -l                       Generate a list file, named by appending '.lst' to
                           input file
  --list-file LIST-FILE    Generate list file, using given name
  -I DIRECTORY             Include directory
  -D IDENTIFIER            Predefine a macro
  -U IDENTIFIER            #undef a predefined macro
  -g,--debug               Produce debugging information
  --rtattr NAME=VALUE      Define a runtime attribute (identifier or quoted
                           string value accepted)
  --weak-symbols           Make all public symbols entries weak
  --core CORE              Core, one of '65816' (defaults to '65816')
  --target TARGET          Target system, one of 'C256', 'F256' or 'SNES'
                           (defaults to embedded/ROM use, if omitted)
  --code-model NAME        Code model, one of 'small', 'compact' or 'large'
                           (defaults to 'large')
  --data-model NAME        Data model, one of 'small', 'medium', 'large' or
                           'huge' (defaults to 'small')
  -h,--help                Show this help text

Options in detail

--version

Displays the name and version of the assembler.

--output-file, -o

Specify the output object file name. If omitted, the output file is derived from the input file name (excluding path) with a .o extension, written to the current directory by default.

This option can also alter the output file name and provide a directory path. The specified directory must already exist.

-l

Generate a list file. The name used is the name of the input file (ignoring any directory path) with a .lst file extension. See also --list-file.

--list-file

Generate a list file. The name of the list file is given as argument to this option. See also -l to generate a list file based on the source filename.

-I

Add a directory to the current include search path. This option can be used multiple times on a command line. The order in which they appear specifies the search order between the directories.

The system include directory is always added last to the search order list.

--include-system

Add a directory to the current system include search path before the provided system include directories. This option can be used multiple times on a command line. The order in which they appear specifies the search order between the directories.

--include-system-after

Add a directory to the current system include search path after the provided system include directories. This option can be used multiple times on a command line. The order in which they appear specifies the search order between the directories.

-D

Define a macro. This takes an argument with the symbol name and optionally an assignment value -Dsymbol[=value]. If no value is given, the macro is given the value 1.

-U

Undefine a macro. This takes an argument with the symbol name to be undefined.

--debug

Generate DWARF symbolic debugging information. In order to get debugging information all the way to the debugger, the linker must also be given this option.

When debugging information is enabled the __CALYPSI_DEBUG__ macro is also defined and set to 1.

-g

Synonym for --debug.

--rtattr NAME=VALUE

This defines a runtime attribute, written to the object file, that the linker can use for object file consistency checks.

--weak-symbols

Make all public symbols in the object file weak. This is normally not needed, but can provide a default library function implementation that is used if no replacement is provided.

In the assembler you can also specify symbols to be exported weak individually using the .pubweak directive.

--core

This option is mostly available for symmetry with other tool chains from Calypsi and future expansion. At the moment only the 65816 core is recognized.

--target

This option is available for symmetry with the compiler. It has the effect of setting the corresponding target preprocessor macro.

--code-model

This option is available for symmetry with the compiler. It has the effect of setting the corresponding code model preprocessor macro.

--data-model

This option is available for symmetry with the compiler. It has the effect of setting the corresponding data model preprocessor macro.