esp-bsasm — the BitScrambler assembler
esp-bsasm assembles programs written for the Espressif BitScrambler instruction set. It translates .bsasm source files into the .bsbin binary format loaded by BitScrambler hardware.
The assembler is a standalone Python package. It is not tied to a particular software framework or host application; ESP-IDF is one of its consumers.
Installation
From PyPI, for command-line and library use:
python -m pip install esp-bsasm
Optional dependency groups:
| Extra | Contents | Install |
|---|---|---|
test |
pytest, pytest-cov, and the language-server extras (so LSP tests run) | pip install "esp-bsasm[test]" |
lsp |
pygls and lsprotocol for the language server | pip install "esp-bsasm[lsp]" |
dev |
commitizen (Espressif rules) for version bumps and changelogs | pip install "esp-bsasm[dev]" |
Installing from a source checkout
Clone the repository and install in editable mode with the extras you need:
git clone <this repository>
cd esp-bsasm
python -m pip install -e ".[test,lsp]"
A plain pip install -e . (no extras) is enough for the command line and the Python API. Editable mode points the installation at your working tree, so code and grammar changes take effect without reinstalling.
To install from source without editable mode (for example to try an unmerged branch as-is):
python -m pip install "esp-bsasm[lsp] @ file:///path/to/esp-bsasm"
Verify the installation:
bsasm --help
bsasm --version
python -c "import bsasm; print(bsasm.__version__)"
Command-line usage
bsasm PROGRAM.bsasm [OUTPUT.bsbin] [--enable-extra-inst NAME[,NAME...]]
If the output path is omitted, the assembler replaces the .bsasm suffix with .bsbin.
Extra instructions are off by default. Pass the names the target supports with --enable-extra-inst. Several names go in one option, separated by commas (--enable-extra-inst addcti,other); repeating the option means the same thing. One name enables a family of mnemonics: addcti enables ADDCTIA, ADDCTIB and their H/L forms. Names are matched case-insensitively. An unknown name is rejected with the list of valid names, and an extra instruction that was not enabled is an error.
Keywords and identifiers are case-insensitive: CFG, Cfg and cfg are the same keyword. The original spelling is kept in token text for diagnostics and editor features, so labels and messages never lose their casing.
You can also invoke the command through Python:
python -m bsasm PROGRAM.bsasm [OUTPUT.bsbin] [--enable-extra-inst NAME[,NAME...]]
The command exits with status 2 when the source cannot be assembled and reports diagnostics with one-based line and column locations.
Python API
import bsasm
program = bsasm.assemble(source_text, ['addcti'])
binary = bsasm.encode(program)
source_text is a BitScrambler assembly program. The second argument, enabled_extra_inst, is a collection of names for the extra instructions the target supports (see bsasm.isa.OPTIONAL_INSTRUCTION_GROUPS). Each name enables one family of mnemonics. Names are matched case-insensitively, and the default is an empty collection. An unknown name raises AssemblerError. An extra instruction that was not enabled raises AssemblerErrors. The returned binary is the contents of a .bsbin file.
Invalid sources raise bsasm.AssemblerErrors; its errors attribute holds every individual AssemblerSyntaxError with its source location — the same full set the CLI reports.
Editor support (VS Code)
A VS Code extension in editors/vscode/ provides live diagnostics, semantic highlighting, a document outline of labels, go-to-definition and find-references on jump targets, and completion for mnemonics, source bits and cfg keys. Diagnostics, highlighting and navigation all come from this package's parser and analyzer - the same code bsasm uses - so they cannot drift from the assembler. Both the CLI and the editor report every error they can recover: the CLI prints each diagnostic on its own line, the editor shows them all at once. The editor does not know the target chip and treats every instruction as available. The assembler is what rejects extra instructions the target did not enable.
Coloring and diagnostics appear only after the language server starts. If esp-bsasm[lsp] is missing from the interpreter in bsasm.python, the file stays plain text; the server log is under Output → BitScrambler Assembly Language Server.
The server is python -m bsasm.lsp, also installed as the bsasm-lsp command.
To set it up from a source checkout:
-
Install the package with the language-server extra:
python -m pip install -e ".[lsp]" -
Build and install the extension (requires Node.js):
cd editors/vscode npm install npm run package code --install-extension esp-bsasm-<version>.vsix
-
Point the extension at the interpreter that has the package installed. It launches
python -m bsasm.lspwith thebsasm.pythonsetting (defaultpython). In VS Code settings:"bsasm.python": "/path/to/python-with-esp-bsasm"
-
Open a
.bsasmfile. Expect live diagnostics for syntax errors, colored mnemonics, source bits, comments and numbers, the label outline in the outline view, completion while typing, and F12 navigation from a jump target to its label.
Documentation
For the language reference, BitScrambler programming model, and binary format, see the ESP32-C5 Technical Reference Manual — BitScrambler and the ESP-IDF BitScrambler programming guide.
Development
Set up a development environment once:
python -m pip install -e ".[test,dev]"
pre-commit install
The grammar is defined in BitScrambler.g4. Generated ANTLR sources are committed under src/bsasm/generated/, so using the package does not require Java or ANTLR to be installed.
After changing the grammar, regenerate the parser with:
python regenerate.py
To verify that the generated files are up to date:
python regenerate.py --check
Run the test suite with:
python -m pytest
The tests include the BitScrambler corpus and command-line coverage. Each corpus program is assembled and compared byte-for-byte against a golden .bsbin compiled by ESP-IDF's reference bsasm.py, so any change to the encoded binary is caught. Linting and formatting run through the installed pre-commit hooks on every commit.
Advanced development: changing the grammar
The grammar is the single source of truth for the syntax of the BitScrambler language. Keep it free of target-language actions and semantic predicates so that it remains a portable ANTLR grammar.
When adding a keyword token, define it before NAME because equal-length lexer matches are resolved in favor of the first rule, and add the keyword to the identifier rule when labels with that spelling must remain valid, such as loopa: or jmp set. Write keyword tokens as lowercase literals (CFG : 'cfg' ;): the grammar sets caseInsensitive = true, so ANTLR folds case into the generated ATN at generation time. Do not spell out [aA][bB]-style fragments — they are redundant and were removed.
Keep glued constructs as single lexer tokens when whitespace is not allowed; for example, AUX_CMP represents bl<=o0 and REL_OPERAND represents l0+a. Write their letters as lowercase too and let caseInsensitive handle uppercase forms. A content statement occupies one line, and a comma always introduces another sub-instruction rather than acting as a dangling separator.
After changing BitScrambler.g4, run python regenerate.py, commit the generated files under src/bsasm/generated/, and add or update tests before submitting the change.
Advanced development: adding an instruction
- Add the mnemonic token, parser rule, operand shape,
subInstralternative, andidentifierentry inBitScrambler.g4. - Regenerate the parser with
python regenerate.pyand commit the generated files. - Add the corresponding statement dataclass to
src/bsasm/model.py. - Add a
visitSub*method tosrc/bsasm/builder.py; for A/B/H/L variants, update the mnemonic-to-counter-and-halves mapping. - Handle the new statement in
src/bsasm/sema.py. If the opcode is an extra instruction, register its name inOPTIONAL_OPCODESinsrc/bsasm/isa.py. - Update
src/bsasm/encoder.pyonly when the instruction introduces a genuinely new hardware opcode pattern; the existing opcode base table already covers the standard opcode families. - Add or update tests under
tests/. When the instruction affects the binary corpus, add a.bsasmsource and regenerate its golden.bsbinwithpython tests/make_golden.py /path/to/esp-idf/tools/bsasm.py. - Update
src/bsasm/lsp.py: add the mnemonic to_MNEMONIC_TOKENS(highlighting and completion derive from that list) and_HOVER_DOCS.
Advanced development: adding a configuration key
- Add the key and its value spellings to the grammar and add a
cfgStmtalternative. - Add the key to the appropriate model enum, together with a dedicated value enum when necessary.
- Add an explicit
visitCfgStmtalternative insrc/bsasm/builder.py; an unhandled alternative should fail loudly rather than fall through to another key. - Add the corresponding handling to
_collect_cfginsrc/bsasm/sema.pyand preserve byte-identical defaults for existing programs. - Update
src/bsasm/encoder.pyonly when the configuration value is represented in the.bsbinheader. - Add regression tests under
tests/. - Update
src/bsasm/lsp.py: add the key/value tokens to_CFG_KEY_TOKENS/_CFG_VALUE_TOKENSand_HOVER_DOCS.
Package structure
The assembler processes a program through these stages:
source text -> parser -> semantic analysis -> binary encoder -> .bsbin
The public API is exposed by bsasm. The command-line entry point is bsasm.cli, and the generated parser implementation is an internal detail.
Compatibility
The binary encoder targets the BitScrambler binary format used by Espressif hardware. The test corpus covers supported instruction forms, configuration values, LUT encodings, and binary header fields. Changes to the grammar or encoder should preserve the existing binary format unless a corresponding hardware-format change is intended.
Metadata
Release files for esp-bsasm 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| esp_bsasm-0.2.0.tar.gz | 78.1 kB | With provenance | Details for esp_bsasm-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| esp_bsasm-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for esp_bsasm-0.2.0-py3-none-any.whl |
Total release size: 141.3 kB
Release files / esp_bsasm-0.2.0.tar.gz
| Download URL | esp_bsasm-0.2.0.tar.gz |
|---|---|
| Size | 78.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c99a7372ea49e06d634c9a317b1ed74ce4be8c2778a0e338bb50ec2dd92f7c03
|
|
BLAKE2b-256 checksum How to use checksums |
a9fb147fe4e6f8659b7b608e7fd9e572d681652b52be6d36dfeb69095957a45f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / esp_bsasm-0.2.0-py3-none-any.whl
| Download URL | esp_bsasm-0.2.0-py3-none-any.whl |
|---|---|
| Size | 63.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11e80a30a91afac1e4be3a0c6da5d09fc029b5a9bcc684c9cceb2f45592d68d8
|
|
BLAKE2b-256 checksum How to use checksums |
040c8e36126229fe27aecb755bd93219e783177d9dfa58eedc12b20d290611d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for esp-bsasm 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for esp_bsasm-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.