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

mixal-emulator

v2.4.0

Published

[![npm version](https://img.shields.io/npm/v/mixal-emulator)](https://www.npmjs.com/package/mixal-emulator) [![WASM Build & Test](https://github.com/CyberZHG/MIXAL/actions/workflows/wasm-build-test.yml/badge.svg)](https://github.com/CyberZHG/MIXAL/actions

Readme

mixal-emulator

npm version WASM Build & Test

JavaScript/WebAssembly bindings for the MIXAL emulator - a MIX assembly language emulator implementing the MIX computer architecture from Donald Knuth's "The Art of Computer Programming".

Installation

npm install mixal-emulator

Quick Start

import { Computer } from 'mixal-emulator';

const computer = new Computer();

computer.loadCodes(`
        ORIG 3000
        ENTA 42
        ADD  =100=
        HLT
`);

computer.executeUntilHalt();

console.log(computer.registerA().value());  // 142
console.log(computer.elapsed());            // Execution cycles

API Reference

Computer

The main class representing the MIX virtual machine.

import { Computer } from 'mixal-emulator';

const computer = new Computer();

Methods

| Method | Returns | Description | |--------|---------|-------------| | loadCodes(code, addHalt?) | void | Load and assemble MIXAL source | | executeUntilHalt() | void | Run until HLT instruction | | executeUntilSelfLoop() | void | Run until self-loop detected | | executeUntilHaltOrSelfLoop() | void | Run until HLT or self-loop | | executeSingle() | void | Execute one instruction | | memoryAt(addr) | ComputerWord | Access memory (0-3999) | | getDeviceWordAt(device, index) | ComputerWord | Access I/O buffer | | line() | number | Current program counter | | elapsed() | number | Total execution cycles | | reset() | void | Reset to initial state |

Register Accessors

| Method | Returns | Description | |--------|---------|-------------| | registerA() | Register5 | Accumulator | | registerX() | Register5 | Extension register | | registerI1() - registerI6() | Register2 | Index registers | | registerJ() | Register2 | Jump address register |

ComputerWord (Register5)

5-byte word used for rA, rX, and memory.

const word = computer.registerA();

// Setters
word.set(12345);
word.setFloat(3.14);
word.setCharacters("HELLO");
word.setBytes(false, 1, 2, 3, 4, 5);      // sign + 5 bytes
word.setMergedBytes(false, 256, 3, 4, 5); // sign + merged bytes
word.setByteAt(2, 42);                    // Set specific byte

// Getters
word.value();           // number - integer value
word.floatValue();      // number - float interpretation
word.getCharacters();   // string - 5 character string
word.getBytesString();  // string - byte representation

Register2

2-byte register used for index and jump registers.

const reg = computer.registerI1();

reg.set(100);
reg.setBytes(false, 1, 2);  // sign + 2 bytes
reg.value();                // number
reg.getBytesString();       // string

Parser

Static utility for parsing MIXAL source lines.

import { Parser, ParsedType } from 'mixal-emulator';

const result = Parser.parseLine("LOOP    LDA  100,1(0:3)", "*", true);

console.log(result.parsedType === ParsedType.INSTRUCTION);  // true
console.log(result.rawLocation);   // "LOOP"
console.log(result.operation);     // "LDA"
console.log(result.rawAddress);    // "100"
console.log(result.rawIndex);      // "1"
console.log(result.rawField);      // "0:3"

executeWithSpec

High-level function for executing code with I/O specifications.

import { executeWithSpec } from 'mixal-emulator';

const result = executeWithSpec(`
        ORIG 3000
        LDA  1000
        HLT
`, {
    // Input: set memory[1000] = 42
    memory: { offset: 1000, values: [42] },

    // Output specification
    outputs: {
        memory: { offset: 1000, length: 1, type: "int" }
    }
});

console.log(result.A.int);           // Register A value
console.log(result.memory[0].value); // 42
console.log(result["execution-time"]); // Cycles

Examples

Finding Maximum Value

import { Computer } from 'mixal-emulator';

const computer = new Computer();

computer.loadCodes(`
X       EQU  1000
        ORIG 3000
MAXIMUM STJ  EXIT
INIT    ENT3 0,1
        JMP  CHANGEM
LOOP    CMPA X,3
        JGE  *+3
CHANGEM ENT2 0,3
        LDA  X,3
        DEC3 1
        J3P  LOOP
EXIT    JMP  *
        ORIG 3500
        HLT
`);

// Setup test data
const n = 100;
computer.registerI1().set(n);
computer.registerJ().set(3500);

let maxVal = 0;
for (let i = 1001; i < 1001 + n; i++) {
    const val = Math.floor(Math.random() * 100000);
    computer.memoryAt(i).set(val);
    maxVal = Math.max(maxVal, val);
}

computer.executeUntilHalt();

console.log(`Expected: ${maxVal}`);
console.log(`Actual: ${computer.registerA().value()}`);
console.log(`Cycles: ${computer.elapsed()}`);

I/O Operations

import { Computer } from 'mixal-emulator';

const computer = new Computer();

computer.loadCodes(`
        ORIG 3000
        IN   100(16)
LIN     JBUS LIN(16)
        OUT  100(17)
LOUT    JBUS LOUT(17)
`);

// Set card reader input (device 16)
computer.getDeviceWordAt(16, 0).setCharacters("HELLO");

computer.executeUntilHalt();

// Read card punch output (device 17)
const output = computer.getDeviceWordAt(17, 0).getCharacters();
console.log(output);  // "HELLO"

Using executeWithSpec

import { executeWithSpec } from 'mixal-emulator';

const result = executeWithSpec(`
        ORIG 3000
        IN   100(16)
LIN     JBUS LIN(16)
        OUT  100(18)
LOUT    JBUS LOUT(18)
`, {
    "card-reader": {
        offset: 0,
        values: "HELLO MIXAL WORLD"
    },
    outputs: {
        "line-printer": {
            offset: 0,
            length: 4,
            type: "text"
        }
    }
});

console.log(result["line-printer"].values);

I/O Device Reference

| Index | Name | Block Size | |-------|------|------------| | 0-7 | magnetic-tape-0 to magnetic-tape-7 | 100 words | | 8-15 | disk-8 to disk-15 / drum-8 to drum-15 | 100 words | | 16 | card-reader | 16 words | | 17 | card-punch | 16 words | | 18 | line-printer | 24 words | | 19 | typewriter | 14 words | | 20 | paper-tape | 14 words |

TypeScript Support

Full TypeScript definitions are included. Import types directly:

import { Computer, ComputerWord, Register2, Parser, ParsedType } from 'mixal-emulator';

const computer: Computer = new Computer();
const reg: ComputerWord = computer.registerA();

Development

# Clone repository
git clone https://github.com/CyberZHG/MIXAL.git
cd MIXAL/wasm

# Install dependencies
npm install

# Build (requires Emscripten)
npm run build

# Run tests
npm test

# Lint
npm run lint

Browser Usage

For browser environments, ensure your bundler supports WebAssembly. The module uses top-level await.

<script type="module">
import { Computer } from './node_modules/mixal-emulator/index.js';

const computer = new Computer();
// ...
</script>

Links