npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

m68k-parser

v1.0.0

Published

Motorola 68000 assembly parser

Readme

M68k Parser

A robust TypeScript parser for Motorola 68000 assembly language that generates an Abstract Syntax Tree (AST). Supports parsing individual lines or entire assembly files with comprehensive error reporting.

Features

  • Parse M68k assembly code into a structured AST
  • Support for all standard M68k instructions and directives
  • Handles multiple addressing modes (immediate, indirect, indexed, PC-relative, etc.)
  • Expression parsing with operators and symbols
  • Register lists and FPU support
  • Macro parameter support
  • Resilient error handling - continues parsing and reports all errors
  • Full TypeScript type definitions
  • Both ESM and CommonJS support
  • Command-line interface for quick parsing

Installation

npm install m68k-parser

Usage

As a Library

Parse a single line:

import { parseLine } from 'm68k-parser';

const result = parseLine('label:    move.w     #1,d0    ; comment');

console.log(result.value);
// {
//   label: { type: 'label', label: 'label', scope: 'global', ... },
//   mnemonic: { type: 'instruction', instruction: 'move', ... },
//   qualifier: { type: 'size', size: 'w', ... },
//   operands: [...],
//   comment: { type: 'comment', content: 'comment', ... }
// }

console.log(result.errors); // Array of parse errors, if any

Parse an entire file:

import { parseFile } from 'm68k-parser';

const source = `
  move.w  #$1234,d0
  bra.s   loop
loop:
  add.l   d0,d1
  rts
`;

const result = parseFile(source);

console.log(result.lines);   // Array of ParsedLine objects
console.log(result.errors);  // Array of all parse errors

Command Line Interface

Parse a file and output the AST as JSON:

# Parse from a file
m68k-parser input.asm

# Parse from stdin
cat input.asm | m68k-parser
echo "move.w #1,d0" | m68k-parser -

API Reference

parseLine(source: string): ParserResult<ParsedLine>

Parses a single line of M68k assembly code.

Returns: ParserResult<ParsedLine>

  • value: The parsed line structure
  • errors: Array of parse errors encountered

parseFile(source: string): ParsedFile

Parses an entire M68k assembly file.

Returns: ParsedFile

  • lines: Array of parsed lines
  • errors: Array of all parse errors from the file

Type Exports

All AST node types are exported for TypeScript users:

import type {
  ParsedLine,
  ParsedFile,
  InstructionNode,
  DirectiveNode,
  OperandNode,
  ExpressionNode,
  // ... and many more
} from 'm68k-parser';

Supported Features

Instructions

All standard M68k instructions including:

  • Data movement: move, movea, movem, lea, etc.
  • Arithmetic: add, sub, mul, div, etc.
  • Logic: and, or, eor, not, etc.
  • Shifts/rotates: lsl, asr, rol, ror, etc.
  • Branches: bra, beq, bne, jmp, jsr, etc.
  • FPU instructions (68881/68882)

Directives

Common assembler directives:

  • dc, ds, dcb - data definition
  • equ, set - symbol definition
  • section, org - program organization
  • include, incbin - file inclusion
  • macro, endm - macro definition
  • And many more

Addressing Modes

  • Immediate: #100, #$FF
  • Data/Address registers: d0-d7, a0-a7
  • Register indirect: (a0), (a0)+, -(a0)
  • Displacement: 10(a0), offset(a0)
  • Indexed: 10(a0,d1.w), (a0,d1.l*4)
  • Absolute: $1000.w, label
  • PC-relative: label(pc), 10(pc,d0)
  • Memory indirect (68020+): ([bd,An,Rn],od)
  • Bitfields (68020+): {offset:width}

Expressions

Full expression support with:

  • Binary operators: +, -, *, /, &, |, ^, <<, >>, etc.
  • Unary operators: -, ~, !
  • Grouping with parentheses
  • Numeric literals: decimal, hex ($FF), binary (%1010), octal (@77)
  • Symbol references
  • Current address (*)

Example Output

Input:

start:  move.w  #$1234,d0

Output:

{
  "label": {
    "type": "label",
    "scope": "global",
    "label": "start",
    "loc": { "start": 0, "end": 5 }
  },
  "mnemonic": {
    "type": "instruction",
    "instruction": "move",
    "loc": { "start": 8, "end": 12 }
  },
  "qualifier": {
    "type": "size",
    "size": "w",
    "loc": { "start": 13, "end": 14 }
  },
  "operands": [
    {
      "type": "immediate",
      "value": {
        "type": "numeric-literal",
        "format": "hex",
        "raw": "$1234",
        "value": 4660
      }
    },
    {
      "type": "data-register",
      "register": "d0"
    }
  ]
}

Error Handling

The parser is resilient and will attempt to parse as much as possible, collecting errors along the way:

const result = parseFile('invalid syntax here\nmove.w d0,d1');

result.errors.forEach(error => {
  console.log(`Line ${error.line}: ${error.message}`);
});
// Still provides parsed output for valid lines

License

MIT - See LICENSE file for details

Author

Graham Bates

Repository

https://github.com/grahambates/m68k-parser