necroassembler
Assemblers for old CPUs and consoles, written in Rust, with bindings for Python and WebAssembly (so the same assembler runs in a browser).
Version 0.9 is a rewrite. The original pure-Python framework (0.8 and earlier) lives on the
legacybranch. See Migrating from the Python version.
| Target | Kind | Notes |
|---|---|---|
6502 |
CPU | MOS 6502, all official opcodes |
65816 |
CPU | WDC 65C816 (Super Nintendo), ca65 syntax, tracks the M/X flags with .smart; .spc700 switches to the sound CPU |
spc700 |
CPU | Sony SPC700, the Super Nintendo's sound CPU |
z80 |
CPU | Zilog Z80, documented and undocumented instructions (IXH/IXL, SLL, DDCB copies) |
lr35902 |
CPU | Sharp LR35902 / SM83 (Game Boy) |
68000 |
CPU | Motorola 68000, every instruction and addressing mode, Motorola source format |
arm |
CPU | ARM7TDMI (ARMv4T) in ARM state, GNU syntax, literal pools; .thumb switches to Thumb |
thumb |
CPU | The same CPU starting in Thumb state |
mips |
CPU | MIPS I / R3000A, little-endian, GNU syntax and macros, GTE commands |
ppc |
CPU | PowerPC 750CL (Gekko / Broadway), GNU syntax and extended mnemonics, paired singles |
8086 |
CPU | Intel 8086 / 8088, NASM syntax |
sh2 |
CPU | Hitachi SH-2 (Saturn, 32X), big-endian, GNU syntax, literal pools |
nes |
platform | 6502 + iNES header, CHR tiles from BMP/PNG |
gameboy |
platform | LR35902 + cartridge header, logo, header and global checksums, 2bpp tiles |
snes |
platform | 65C816 + Super Nintendo cartridge (LoROM / HiROM) with header, vectors and checksum, hardware register symbols |
sms |
platform | Z80 + TMR SEGA header with checksum, 4bpp tiles |
genesis |
platform | 68000 + Mega Drive / Genesis header, ROM end and checksum, 4bpp tiles |
amiga |
platform | 68000 + AmigaOS executable (code, data and bss hunks) with relocations, custom chip symbols |
gba |
platform | ARM7TDMI + Game Boy Advance header and complement check, 4bpp/8bpp tiles, I/O register symbols |
psx |
platform | R3000A + PlayStation executable (PS-X EXE), hardware register symbols |
gamecube |
platform | Gekko + GameCube / Wii executable (DOL), hardware register and SPR symbols |
dos |
platform | 8086 + MS-DOS .COM program, loaded at offset $100 |
saturn |
platform | SH-2 + Sega Saturn program with an IP.BIN-style header, as a cartridge image, hardware register symbols |
Every CPU of the legacy Python version is now ported (x86 as the 16-bit 8086 only).
How it is tested
- Unit tests for the core and every CPU:
cargo test. - Conformance against reference assemblers, over every instruction form and many invalid ones
(tools/conformance): ca65 for the 6502 and the 65C816, WLA-DX
for the SPC700, GNU as for the Z80, the 68000, ARM, Thumb, MIPS, PowerPC and the SH-2, rgbasm for
the Game Boy, NASM for the 8086. Every form the reference accepts encodes identically, apart from
the deliberate differences listed in the script (for example, the 68000 rejects
subq.b #1,a0, which GNU as accepts although the CPU cannot execute it). - Emulator tests (tests/emulator): small programs (CRC-16, multiplication, macros, block moves…) are assembled into real ROMs, run in MAME (NES, Game Boy, Master System, Super Nintendo, Mega Drive, Amiga 500, Game Boy Advance, PlayStation, Saturn) or Dolphin (GameCube, read through its GDB stub), and their results are read back from RAM. MS-DOS programs run in DOSBox and write their results to a file. The Game Boy, Super Nintendo (its sound CPU), Amiga, GBA, PlayStation and Saturn need a system ROM: free stand-ins written for this assembler live in tests/emulator/support (the Amiga one loads and relocates the test's AmigaOS executable, hunk by hunk, the PlayStation one the PS-X EXE and the Saturn one the program after its header, so the executable formats are tested too; the SNES one speaks the sound CPU's upload protocol).
The tools run in a Docker image: docker build -t necro-tools tools/docker (give the emulator
tests --shm-size=1g, as Dolphin keeps the emulated memory in /dev/shm).
Command line
cargo install necro-cli # or, from a checkout: cargo install --path crates/necro-cli
necro -t gameboy game.s -o game.gb
necro -t nes -I include -D DEBUG=1 --symbols game.sym --listing game.lst game.s
necro --targets
Python
pip install necroassembler
Wheels are published for Windows and Linux (x86-64); elsewhere pip builds it from source, which
needs Rust. From a checkout: pip install maturin, then cd crates/necro-py && maturin develop --release.
>>> from necroassembler import assemble
>>> r = assemble("LDA #$11\nSTA $1111", "6502")
>>> r.bytes
b'\xa9\x11\x8d\x11\x11'
>>> assemble("start: JP start\n.include \"lib.s\"", "z80", files={"lib.s": b"NOP"}).symbols
{'start': 0}
>>> assemble("LDA (", "6502")
necroassembler.AssemblyError: <input>:1:5: error: expected a value
Without files, includes are read from disk (relative to the source, then include_paths).
python -m necroassembler -t nes game.s works too.
Browser (WebAssembly)
The playground is online at https://rdeioris.github.io/necroassembler/, rebuilt from master on
every push. To run it locally:
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --version 0.2.127
sh tools/build-web.sh # builds web/pkg
python -m http.server -d web # the playground in web/index.html
import init, { assemble, targets, mnemonics } from "./pkg/necro_wasm.js";
await init();
const r = assemble(source, "gameboy", { "tiles.png": pngBytes, "lib.s": "NOP" });
if (r.ok) save(r.bytes); // Uint8Array, plus r.symbols, r.listing, r.warnings
else for (const d of r.diagnostics) mark(d.line, d.column, d.length, d.message);
The playground's Tools menu has asset and sound tools for the selected target: tile, map and
palette editors, image converters, sound designers, trackers and header builders for each console,
plus a memory map, a cycle counter, a table generator and a font builder for any target. Every tool
ends in source code for the target (tables, constants, .incbin of a project file) inserted into
the editor. Project files are kept in the browser and passed to the assembler for .incbin and
.include. web/tools/README.md explains how the tools are built;
node tools/web/run_tests.mjs checks that what they emit assembles.
Hardware reference
docs/reference has one document per target: the hardware, its memory
maps, the register names the assembler predefines, and every instruction of its CPUs with the syntax
the assembler accepts, its size and its clock cycles. The documents are generated from the data in
tools/docs/data by node tools/docs/build.mjs, which assembles every example (so the syntax and
the sizes are the assembler's own) and fails if the assembler knows an instruction the data leaves
out. Cycle counts and memory maps come from the sources each document lists.
The playground's Reference button shows the same documents, opened at the current target's
section, with a search box that filters the instruction and register tables. The build also copies
them to web/reference for it (tools/build-web.sh runs it when node is installed).
Syntax
- Numbers:
123,$7F,0x7F,7Fh,%1010,0b1010,1010b,@17,0o17,'A'. - Expressions with C precedence:
+ - * / % << >> & | ^ ~ ! && || == != < <= > >=, parentheses,<x/>x(low and high byte),$or*for the current address. - Labels:
name:; local labels.loop/@loopbelong to the last global label. ARM, MIPS, PowerPC and the SH-2 also have GNU numeric labels:1:can be defined many times,1brefers to the nearest one before and1fto the nearest one after. - Constants:
name = expr,name equ expr,name .set expr. Assigning a name twice makes it a variable. - Forward references are resolved by repeated passes, so
LDA valuepicks zero page whenvaluelater turns out to be below $100. Force a size withLDA.w/LDA a:value(6502). - Comments:
;,//,/* … */. For MIPS, PowerPC and the SH-2, as in GNU as,;separates two statements on one line (li r3, 0; blr); at the start of a line it is still a comment. The SH-2 also takes!comments, and#ones at the start of a line.
Directives
| Directive | Meaning |
|---|---|
.org addr [end] |
set the address; with end, the region is padded up to it |
.goto addr / .pad |
fill up to an address |
.align n |
fill up to a multiple of n |
.db .dw .dd .dq (.byte, .word, .long, defb, dc.b…) |
data, little or big endian as the CPU is |
.float / .double (.single, dc.s, dc.d) |
IEEE 754 values: decimals (1.25, -1.5e-3) or integer expressions |
.ascii / .asciiz |
strings, with \n \t \0 \xHH escapes |
.fill n [,v] / .ds |
n bytes of v (default .fillvalue, 0) |
.ram n |
reserve address space without emitting bytes |
.logical addr … .endlogical (.phase / .dephase) |
assemble for the address the code will be copied to, while the bytes stay where they are |
.include "f" / .incbin "f" [,offset [,length]] |
source / binary inclusion |
.inccsv, .inccsv_le16, .incjson |
numbers from CSV or JSON |
.macro NAME a, b … .endmacro |
macros; \@ makes labels unique per expansion |
.repeat n [, i] … .endrepeat |
repetition with an optional counter |
.if / .elif / .else / .endif, .define |
conditional assembly |
.error, .warning, .assert expr [, msg] |
diagnostics |
.db_to_ascii, .dw_to_ascii |
numbers as decimal text |
Platforms add .cartridge* directives for their headers and .tiles "image" to convert indexed BMP or
palette PNG images.
68000: Motorola source format
The 68000, genesis and amiga targets read sources written for Devpac, asm68k or vasm:
* comment line
CUSTOM equ $dff000
rsreset
obj_x rs.w 1 structure offsets: obj_x = 0
obj_y rs.w 1 obj_y = 2
PUSH macro
move.\0 \1,-(sp) \1..\9 are the arguments, \0 the size (PUSH.L)
endm
start lea CUSTOM,a6 a label in column 1 needs no colon
PUSH.l d0 anything after the operands is a comment
ifne DEBUG
move.w #$0F00,$180(a6)
endc
.loop dbra d0,.loop local label
rts
dc.b 'it''s',0 single-quoted strings; 'DOS' is also a number
even
end
- Directives work with or without a dot (
org,include,incbin,incdir,even,cnop,rept/endr,if/ifeq/ifne/ifgt/ifge/iflt/ifle/ifd/ifnd/else/endc,macro/endm,NARG,rsreset/rsset/rs.b/rs.w/rs.l,dc/ds/dcb,end).xdef,xrefandoptare accepted and ignored;sectionmakes separate hunks on theamigatarget and is ignored elsewhere. name equr d0names a register andname reg d0-d3/a0a register list formovem.incdir "dir"adds a directory whereincludeandincbinlook for files.*starts a comment at the beginning of a line or after the operands.- Addressing modes:
d0,a0,(a0),(a0)+,-(a0),8(a0)or(8,a0),8(a0,d1.w)or(8,a0,d1.l),$1234.w,$12345678.l(or plain, picked by value),label(pc),label(pc,d0.w),#value;spisa7; a%before register names (%d0) is accepted. - An index register without a size is
.W, as Motorola defines it (GNU as uses.L). - Unsized branches are short when the target is in range, otherwise word;
.s/.band.wforce a size. As with the other CPUs, a numeric branch or PC-relative operand is an address. - As GNU as and vasm do,
ADD/SUB #1..8becomeADDQ/SUBQ,MOVE.L #-128..127,DnbecomesMOVEQand0(An)becomes(An); absolute addresses that fit in a sign-extended word use the short form.
Amiga executables
AmigaOS loads a program wherever it finds memory, so the amiga target writes hunks with RELOC32
tables. Without section the whole program is one code hunk in chip RAM. section name,type[,mem]
starts (or resumes) a hunk: the type is code, data or bss, the memory chip, fast or
omitted for any; code_c, data_f, bss_c and the bare code/data/bss lines are shorthands.
A bss hunk can only reserve space (ds).
Every absolute address of a label must be a 32-bit value the loader can fix: labels are always
assembled as long absolute addresses, MOVEQ/ADDQ are not used for label values, and the
assembler reports anything else that depends on the load address (dc.w label, label>>16, a
PC-relative reference to another hunk). .org cannot be used.
examples/amiga/copper.s is a complete demo: copper bars and a four-channel Paula tune.
ARM and the Game Boy Advance
The arm, thumb and gba targets read GNU as syntax for the ARM7TDMI:
.cartridge @ GBA header at the start of the ROM
.cartridge_title "DEMO"
.arm
start: ldr r0, =REG_DISPCNT @ literal pool, or mov/mvn when the value fits
mov r1, #0x0403
strh r1, [r0]
adr r0, main + 1
bx r0 @ to Thumb
.ltorg
.thumb
main: push {r4, lr}
ldr r4, =VRAM
...
- Conditions and the
ssuffix go in either order (addeqsoraddseq); all ARMv4T instructions, includingmrs/msr, long multiplies, halfword and signed loads,swp,ldm/stmwith every addressing mode, andpush/pop. - Immediates that need it use the GNU swaps (
mov r0, #-1ismvn r0, #0,addof a negative value issub, and so on). ldr rd, =valueusesmov/mvnwhen it can, otherwise a literal pool, written at.ltorg/.poolor at the end of the source..arm/.thumb/.code 16|32,.word(32-bit),.hword,.align(power of two),.balign;@starts a comment.- The
gbatarget starts at 0x08000000 and computes the header complement check;.cartridge_logo "file"copies the 156-byte Nintendo logo from a file you supply (it is not included)..tilesconverts images to 4bpp tiles,.tiles8to 8bpp.
MIPS and the PlayStation
The mips and psx targets read GNU as syntax for the R3000A:
.set noreorder
start: la $a0, GP1 # psx hardware registers are predefined
lui $t0, 0x0300 # GP1(03h): display on
sw $t0, 0($a0)
li $t1, 0x12345678 # lui + ori; li/la pick the shortest form
lw $t2, table($t3) # lui $at + addu + lw for a label
blt $t2, $t1, start # slt $at + bne
nop # delay slots are yours to fill
rtps # GTE commands by name
table: .word 1, 2, 3
- Instructions are never reordered: write what goes in each branch and load delay slot, as with
GNU's
.set noreorder(.set reordergets a warning). - The GNU macros expand exactly as GNU as does (
li,la,move,b,blt/bgeu...,mul,abs,seq...,rol/ror,ulw/usw, loads and stores from a label or a 32-bit address, ALU instructions with large immediates) and use$at. Labels always take two instructions (lui+addiu), so the code size never depends on where it ends up. %hi(x)and%lo(x)split an address forluiand a 16-bit offset.div rs, rtis the plain instruction (GNU as adds a divide-by-zero check to that form); the three-operanddiv/remmacros are not available.- GTE:
rtps,rtpt,nclip,op,dpcs,intpl,mvmva sf, mx, v, cv, lm,ncds,cdp,ncdt,nccs,cc,ncs,nct,sqr,dcpl,dpct,avsz3,avsz4,gpf,gpl,ncct(with optionalsfandlmoperands;sfdefaults to 1),cop2 n,mfc2/mtc2/cfc2/ctc2,lwc2/swc2. #starts a comment;.wordis 32 bits,.half16,.align naligns to 2^n bytes.- The
psxtarget writes a PS-X EXE: code from $80010000 after the 2048-byte header, started at its first byte with the stack at $801FFFF0..psx_entry,.psx_stack,.psx_gp,.psx_bssand.psx_region na|eu|jpchange the header. Kernel calls go through the BIOS as usual (li $t1, n/jal 0xA0).
examples/psx/cube.s is a complete demo without BIOS calls: a cube rotated and projected by the GTE, drawn as Gouraud-shaded triangles, with six-voice SPU music.
necro -t psx examples/psx/cube.s -o cube.exe
PowerPC, the GameCube and the Wii
The ppc and gamecube targets read GNU as syntax for the 750CL (Gekko in the GameCube, Broadway
in the Wii):
start: lis r3, table@ha # @ha/@l split an address for lis + addi or a load
addi r3, r3, table@l
li r4, 8
mtctr r4
loop: lwzu r5, 4(r3)
cmpwi cr1, r5, 0
beq- cr1, done # an optional CR field and prediction hint
rlwinm r5, r5, 2, 0x3fc # a mask instead of MB, ME
bdnz loop
done: psq_l f1, 0(r3), 0, 0 # paired singles
ps_add f1, f1, f1
blr
table: .long 1, 2, 3
- Registers are numbers (
addi 3,1,8) or names:r0..r31(sp,rtoc),f0..f31,cr0..cr7, with or without%. In CR bit operandscr0..cr7,lt,gt,eq,soandunhave their values (crand 4*cr6+eq, 4*cr2+eq, 4*cr5+lt). - All the 750CL instructions (integer, floating point, supervisor, cache) with their
.andoforms, the Gekko paired-single instructions, and GNU's extended mnemonics:li,lis,la,mr,not,sub,subi,cmpw/cmplwi,slwi,srwi,clrlwi,extrwi,inslwiand the other rotates, every conditional branch (bne,bgelr,bltctrl,bdnz,bdnzt,bt,bf... with+/-hints), traps,mflr/mtctr/mtsprg/mtibatu/mftband the other SPR moves,crset/crclr/crmove/crnot. - Unlike GNU as, a register name of the wrong kind (
add f1, r2, r3) is an error, andmftbis accepted for the 750. #starts a comment;.longis 32 bits,.shortand.word16,.align naligns to 2^n bytes.- The
gamecubetarget writes a DOL: code from $80003100 after the 256-byte header, started at its first byte..dol_entryand.dol_bss start, sizechange the header. Hardware registers (VI,PI,VI_TFBL,GX_FIFO...) and the Gekko SPRs (HID0,HID2,GQR0..GQR7...) are predefined. Wii programs use the same format (-t wiiis the same target): Dolphin runs a DOL as a Wii program when its code usesHID4.
examples/wii/cube.s is a complete demo for the Wii without an SDK: it sets
up the GPU through the write-gather pipe with its own command macros, rotates the cube with a
matrix in the transform unit, and plays the PlayStation demo's song, synthesized by the CPU into an
audio DMA ring buffer. tools/emulator/record.py -t wii records it in Dolphin.
necro -t wii examples/wii/cube.s -o cube.dol
8086 and MS-DOS
The 8086 and dos targets read NASM syntax for the 8086 and 8088 and produce the same bytes as
NASM: the shortest encodings, 83 with a sign-extended byte where it fits, and segment prefixes
only where written.
- Registers
al..bh,ax..di,es/cs/ss/ds; memory as[bx+si+disp],[bp-2],[1234h], with a segment either inside or before the brackets ([es:di],es:[di]). byte,wordanddwordgive a size where no register does (inc byte [bx]);short,nearandfarchoose a jump (jmp short x,call far [bx],jmp 1234h:5678h). Conditional jumps,loopandjcxzhave only the short form, so a target out of range is an error (NASM silently inverts the condition around a near jump).- Prefixes go on their own or before the instruction:
rep movsb,lock xchg [bx], ax,es lodsb. db/dw/dd,resb/resw/resd,times n …,incbin,align,org,bits 16andcpu 8086work as in NASM, as do$and$$(the start of the program). Labels beforedband the other data words need no colon;.namelabels are local.- The
dostarget writes a .COM program: DOS loads it at offset $100 with every segment register set to its segment, so sources that start withorg 100hassemble unchanged. The image can be up to 65,024 bytes.
necro -t dos hello.s -o hello.com
dosbox hello.com
examples/dos/logo.s draws the necroassembler logo in VGA mode 13h over a plasma, with a scroller and the PlayStation demo's song on the PC speaker. Apart from the scroller, all of the animation is palette cycling, so each frame needs very little CPU time.
necro -t dos examples/dos/logo.s -o logo.com
dosbox logo.com
65C816, SPC700 and the Super Nintendo
The 65816 target reads ca65 syntax. The width of an immediate depends on the M and X flags, which
an assembler cannot see: .a8 / .a16 and .i8 / .i16 (or .accu / .index 8|16) say what
they are, and after .smart necroassembler follows rep and sep with constant operands.
Addresses take the shortest form the instruction has (direct page, absolute, long); z:, a: and
f: before the operand, or .b, .w and .l after the mnemonic, force one. mvn and mvp
take two banks, as #$7E or as addresses (whose bank byte is used, as in ca65).
The spc700 target, for the sound CPU, reads the usual syntax (WLA-DX, bass): !$1234 is an
absolute address and a plain one is on the direct page, with $12+x, [$12+x], [$12]+y, (x)+,
$12.3 (a bit) and /$12.3 (its complement). A small address is never quietly made absolute,
as the P flag can move the direct page.
The snes target writes a cartridge, LoROM by default. Assembly starts at $008000 and the bytes
go into the ROM in source order (.org $018000 $01FFFF fills a bank up to its end). .cartridge
asks for the internal header: at the end the ROM is padded to a power of two and the title
(.cartridge_title), map mode (.cartridge_hirom, .cartridge_fastrom), sizes
(.cartridge_sram), region, version, interrupt vectors (.cartridge_reset, .cartridge_nmi,
.cartridge_irq… and the emu_ ones) and checksum are filled in. The sound CPU's code goes in the
same source after .spc700, inside .logical $0200 … .endlogical so that it is assembled for
the address the boot ROM copies it to; .p816 switches back.
.cartridge
.cartridge_title "HELLO"
.cartridge_reset start
.smart
start: sei
clc
xce ; native mode
rep #$30 ; 16-bit A, X, Y: the immediates below are 16-bit
ldx #$1FFF
txs
sep #$20
lda #$0F
sta INIDISP ; full brightness
.smart follows the source text, not the program's flow: after a jsr to a routine that ends in
another width, write the rep or sep again.
examples/snes/logo.s is the MS-DOS logo demo for the Super Nintendo. The screen comes on at once and the picture is drawn while it shows: the 65C816 draws the logo and the title into the work RAM, then goes down the picture a row of tiles at a time, filling in the plasma and turning the row into 8-bit bitplanes, which the vertical blank interrupt copies to the VRAM as background 1 of mode 3. The scroller is background 2, with each new letter's tiles built during the frame and copied in the vertical blank. The plasma, the light on the skull, the eyes and the gradients are colour RAM changes, written by DMA in every vertical blank. The song is SPC700 code in the same source, uploaded through the sound CPU's boot ROM: a saw bass, a square arpeggio and a triangle lead (both through the DSP's echo), a sine kick that falls in pitch, and noise for the snare and hi-hat.
necro -t spc700 tests/emulator/support/snes_ipl.s -o roms/snes/spc700.rom
necro -t snes examples/snes/logo.s -o logo.sfc
mame snes -rompath roms -cart logo.sfc
MAME warns that spc700.rom has the wrong checksum, because it is our own stand-in for the boot
ROM, and runs it anyway.
SH-2 and the Sega Saturn
The sh2 and saturn targets read GNU as syntax for the SH-2 (big-endian), with the same bytes
as GNU as:
- Registers
r0..r15(sp),sr,gbr,vbr,mach,macl,pr; operands#imm,@rn,@rn+,@-rn,@(disp,rn),@(r0,rn),@(disp,gbr),@(r0,gbr)and@(disp,pc); mnemonics with their size (mov.l,mac.w) and conditions (cmp/eq,bf/s). - Branch targets and the labels of
mov.w label,rn,mov.l label,rnandmova label,r0are addresses. Delay slots are never filled or checked: the instruction after a delayed branch runs before the branch is taken. An out-of-range conditional branch is an error (GNU as silently replaces it with a longer sequence). mov.l #value,rnandmov.w #value,rnload any constant from a literal pool, placed at the next.ltorg/.poolor at the end of the source; put it where it is not executed..wordis 16 bits and.long32;.align naligns to 2^n bytes, filling code withnop.- The
saturntarget assembles the program for $06004000, in the work RAM, and writes a cartridge image: a 256-byte header laid out like a disc's IP.BIN (.saturn_title,.saturn_product,.saturn_version,.saturn_date,.saturn_area,.saturn_stack), then the program, padded to a power of two. The stand-in BIOS of the tests (tests/emulator/support/saturn_bios.s) copies it to the work RAM and starts it, the way the real BIOS starts a disc's first file; the real BIOS does not boot cartridges.
examples/saturn/logo.s is the MS-DOS logo demo for the Saturn. The picture is a 256-colour VDP2 bitmap and the scroller a second bitmap moved by the VDP2's scroll registers. The plasma, the light on the skull and the eyes are colour RAM changes made in every vertical blank. The song plays on the SCSP, driven by the SH-2 alone with the 68000 left off: six slots for a saw bass, a square arpeggio, a triangle lead with vibrato, a kick that falls in pitch, and noise for the snare and hi-hat.
necro -t sh2 tests/emulator/support/saturn_bios.s -o roms/saturn/mpr-17933.bin
necro -t saturn examples/saturn/logo.s -o logo.bin
mame saturn -rompath roms -cart logo.bin
MAME also wants the CD block's ROMs (cdb105.bin, cdb106.bin, ygr022.bin) and sega_100a.bin
to exist; empty files of the right size will do, as the emulator tests do (MAME warns about their
checksums).
A Game Boy example
This is examples/gameboy/logo_scroll.s:
.org $0000 $7fff ; the size of the cartridge must be 32k (second bank at $4000 can be bank-switched)
.goto $100 ; cartridge header must be at $100
.cartridge
.cartridge_title "NECROBOY"
.goto $150 ; start of the program
LD SP, $FFFE ; setup stack
CALL turn_off_lcd ; before accesing vram we need to turn off the lcd
; file tiles
LD HL, start_of_tiles
LD BC, end_of_tiles-start_of_tiles ; label math is so handy...
LD DE, VRAM
fill_tiles:
LD A, (HL+)
LD (DE), A
INC DE
DEC BC
LD A, B
OR C
JR NZ, fill_tiles
; clear tilemap
LD HL, TMAP0
LD BC, 32*32 ; integers and labels have math by default
clear_tilemap:
LD A, 28 ; '28' is the empty tile (see below)
LD (HL+), A
DEC BC
LD A, B
OR C
JR NZ, clear_tilemap
; fill tilemap
LD HL, start_of_tilemap
LD BC, end_of_tilemap-start_of_tilemap
LD DE, TMAP0
fill_tilemap:
LD A, (HL+)
LD (DE), A
INC DE
DEC BC
LD A, B
OR C
JR NZ, fill_tilemap
CALL turn_on_lcd
XOR A
LD (scroll), A
loop:
CALL wait_vblank
LD A, (scroll)
LD (SCX), A ; increment scroll x
LD (SCY), A ; increment scroll y
INC A
LD (scroll), A
JP loop
wait_vblank:
LD A, (LY)
CP 144
JP NZ, wait_vblank
RET
turn_off_lcd:
CALL wait_vblank
XOR A
LD (LCDC), A
RET
turn_on_lcd:
LD A, %10010001 ; enable lcd and background
LD (LCDC), A
RET
start_of_tiles:
.tiles "docs/necroassembler_112x16.bmp"
.fill 16 ; this is the tile 28 (empty)
end_of_tiles:
start_of_tilemap: ; the 112x16 logo is 14x2 tiles, at the top left of the 32x32 map
.repeat 14, i
.db i
.endrepeat
.fill 18, 28
.repeat 14, i
.db 14 + i
.endrepeat
end_of_tilemap:
scroll = $C000 ; a byte of work RAM
necro -t gameboy examples/gameboy/logo_scroll.s -o logo.gb
.cartridge writes the header (and points the entry at $150); the logo, ROM size and both
checksums are filled in when assembly ends. .tiles converts the 4 colour image to Game Boy tiles.
Migrating from the Python version
pip install necroassemblerinstalls the Rust-backed package. The oldAssembler*classes are gone: callnecroassembler.assemble(source, target)on the whole source instead. Code that needs them can stay onpip install "necroassembler<0.9", whose source is on thelegacybranch.- A number given to a branch (
BNE 5,JR 3) is now the target address, as in every other assembler, not a raw displacement. .db_to_asciialways pads with zeros.- The NES header no longer moves the current address: code after
.cartridgestarts at.org. .sectionand.exportare accepted with a warning; ELF output is not ported yet.- Errors are reported all together with file, line and column, instead of stopping at the first one.
Releasing
Set the version in Cargo.toml ([workspace.package] and the necroassembler dependency of
crates/necro-cli), commit, then push a matching tag:
git tag -a v0.9.1 -m "necroassembler 0.9.1"
git push origin v0.9.1
The Release workflow tests the code, builds the Python wheels (Linux x86-64 and ARM64, Windows, macOS Intel and Apple Silicon) and the source package, publishes them on PyPI and the crates on crates.io, and makes a GitHub release with the wheels. Running it by hand from the Actions tab builds and tests everything without publishing.
License
MIT
Metadata
Release files for necroassembler 0.9.1
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 |
|---|---|---|---|---|
| necroassembler-0.9.1.tar.gz | 189.7 kB | With provenance | Details for necroassembler-0.9.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| necroassembler-0.9.1-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for necroassembler-0.9.1-cp39-abi3-win_amd64.whl |
| necroassembler-0.9.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for necroassembler-0.9.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| necroassembler-0.9.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for necroassembler-0.9.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| necroassembler-0.9.1-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for necroassembler-0.9.1-cp39-abi3-macosx_11_0_arm64.whl |
| necroassembler-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details for necroassembler-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl |
Total release size: 3.7 MB
Release files / necroassembler-0.9.1.tar.gz
| Download URL | necroassembler-0.9.1.tar.gz |
|---|---|
| Size | 189.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
45a08aa44a30fc648367ab523ef7fc0f96efa66ccf906130fb884d2e7a170805
|
|
BLAKE2b-256 checksum How to use checksums |
b18445e7a95b230153373cd648863fbf5a4c89d65b634c9ae835d9652df90814
|
| 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 Dec 6, 2026.
Transparency logRelease files / necroassembler-0.9.1-cp39-abi3-win_amd64.whl
| Download URL | necroassembler-0.9.1-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 641.3 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2baafdde33644de32012a1f67f769a17936e42834c76b38818c3ebe830eabd0b
|
|
BLAKE2b-256 checksum How to use checksums |
69f6aee32439e43be4670c3b175ca26ec3cf1a6ed3c51e486653b9fa6700c57d
|
| 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 Dec 6, 2026.
Transparency logRelease files / necroassembler-0.9.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | necroassembler-0.9.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 750.7 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bcc3eafa47398688ced53c7afc121e0ef986b2e4eaf77fd776ac8f3a1ccf64d3
|
|
BLAKE2b-256 checksum How to use checksums |
10223c1082071e4111a289de331830f5ab10db20399bd3c540978e33103843e0
|
| 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 Dec 6, 2026.
Transparency logRelease files / necroassembler-0.9.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | necroassembler-0.9.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 741.3 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0d5c20610b13ff7f2d59918ebb1aae062553b070e1317630a4f272b7516bd049
|
|
BLAKE2b-256 checksum How to use checksums |
66a7c713c09dc357077874f7c390c9abb58104ca3e3c1c2e55bf054e0b280318
|
| 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 Dec 6, 2026.
Transparency logRelease files / necroassembler-0.9.1-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | necroassembler-0.9.1-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 684.0 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e0b8e1b233e1e931c7e303ced8fc831a1b4f2f49222d44ca5ea0c08419e5a0b3
|
|
BLAKE2b-256 checksum How to use checksums |
d6f756e876d4a75fbe1e509460f4690a4dec4dae282153a5e048f32bc3e99176
|
| 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 Dec 6, 2026.
Transparency logRelease files / necroassembler-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | necroassembler-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 723.2 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
3b5579e675b2e7cf859d2b313e90df62a0c87567ad05cf525933ae9511227b3c
|
|
BLAKE2b-256 checksum How to use checksums |
6de31d86abd9c41897d561a64a109c933af3cbdbb46f9ce7b73eb2fa5256b8d1
|
| 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 Dec 6, 2026.
Transparency logSecurity for necroassembler 0.9.1
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
All 6 files in this release have been uploaded with provenance metadata.
Attestation for necroassembler-0.9.1.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 Dec 6, 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.