272 bytes · 16-bit x86 DOS
AttoChess The world’s smallest chess engine
A playable chess engine in just 272 bytes, created by Nicholas Tanner. It draws the board, reads your moves, and searches four plies deep.
- Architecture
- 80186 · DOS
- Search
- Four plies
- By
- Nicholas Tanner
- Released
- 2026 · MIT
Derived from Dmitry Shechtman’s LeanChess.
Reduced chess rules. Read the limitations.
Play AttoChess
Select two squares or type coordinates, e.g. e2e4.
Before you play
You play White. After selecting or typing a move, press Enter or Play move. The 272-byte program runs in an emulated DOS machine and searches four plies before replying.
Coordinates are trusted, not checked for chess legality. No castling, en passant, promotion, or full check/checkmate adjudication. The engine keeps playing losing replies and stops when no move is generated.
Pieces view translates the DOS letters into chess symbols. ASCII shows the engine’s original piece letters: uppercase for White, lowercase for Black.
Executable contents
The hexadecimal listing contains all 272 bytes of ATTOCHES.COM, including executable instructions, vector pointers, and table data.
Select a category to highlight its bytes. Each pair of hexadecimal digits represents one byte.
Read the disassemblyHistorical comparison
AttoChess is derived from LeanChess and retains its padded board representation and recursive material search. Its executable is sixteen bytes smaller.
The programs below target different platforms and implement different reduced rule sets.
| Year | Program / author | Platform | Executable size, to scale | Bytes |
|---|---|---|---|---|
| 1982 | 1K ZX ChessDavid Horne | Sinclair ZX81 | 672bytes | |
| 2015 | BootChessOlivier Poudade | x86 boot sector | 487bytes | |
| 2015 | Toledo AtomchessÓscar Toledo G. | x86 DOS .COM | 352bytes | |
| 2019 | LeanChessDmitry Shechtman | x86 DOS .COM | 288bytes | |
| 2026 | AttoChessNicholas Tanner | x86 DOS .COM | 272bytes |
The previous AttoChess release was 276 bytes. Its exact source and binary are preserved.
Size optimizations
Display, input, and search optimizations reduced the LeanChess executable from 288 to 276 bytes. Four additional changes reduced it to 272 bytes and are accompanied by verification evidence.
The ten entries below describe these changes and include the relevant assembly code.
01Direct board output
The original implementation renders the position into a separate buffer: it walks the board, transforms each square into a printable character, stores it, appends a $ terminator, and prints the whole string with DOS function 09h (int 21h). That path costs a buffer pointer setup, the copy loop's store, the terminator write, and, because the buffer lives after the board, a reserved board array in the image.
AttoChess replaces this rendering path. The board's border columns are laid out as CR, LF, CR, LF (0Dh, 0Ah, 0Dh, 0Ah) rather than the 08h filler LeanChess used. CR and LF both have bit 3 set, so every existing border/color mask test fires exactly as before, except now the raw board bytes are already a printable frame. The display loop streams each byte straight to the console with int 29h (DOS fast console output): borders become newlines, empty squares become NULs, and only real pieces take the ASCII transform.
main_loop:
mov si, board_db + 24 ; row 2 (black back rank), col 0
mov cl, 98 ; 8 rank rows + final CR,LF (CH=0)
disp_loop:
lodsb ; read square contents
test al, 30h ; piece?
jz disp_cont ; no: emit raw (CR / LF / NUL)
inc ax ; zero-align king
and al, 27h ; isolate piece type + black/lowercase bit
add al, 4Bh ; K, N, B, P, Q, R (upper/lower by color)
disp_cont:
int 29h ; fast console output of AL
loop disp_loop
That takes out the render buffer, its pointer setup, the $ terminator, the int 21h/09h string print, and the reserved board array in the file image.
02No BIOS mode-set
The original opens with int 10h to force BIOS display mode 0. AttoChess omits this call and explicitly initializes the direction flag and row count:
start:
cld ; DF is not guaranteed clear at entry
mov cx, 13 ; row count (entry CX is not guaranteed)
Streaming through int 29h works in whatever video mode you happen to be in, so the mode-set is not needed.
03The input decoder folds every constant into one base address
Reading a move means turning two typed characters (a file and a rank) into a board address. The original does this in stages: read the file char, add it, read the rank char, mask it down with and al, 0Fh, load 12 into ah, mul to get the row offset, and subtract.
AttoChess collapses the arithmetic by pre-folding the ASCII bias constants into the base address and letting 16-bit pointer math wrap around mod 64K. The normalization step and the separate multiply setup both disappear:
read_sub:
mov bp, di
mov di, board_db + 123 + 0CE0h ; base pre-folds the ASCII offsets
mov ah, 01h
int 21h ; read file char
add di, ax ; AX = 0100h + file char
int 21h ; read rank char
imul ax, 12 ; AX = 12 * (0130h + rank digit)
sub di, ax ; land on the target square
imul ax, 12 (an 80186 immediate-form multiply) replaces the mov ah,12 + mul ah pair, and the wrap-around base makes the explicit and al, 0Fh input mask unnecessary.
04The source loop leaves CX alone, so depth is never reloaded
Inside the recursive search, the original scans candidate source squares with a counted loop (mov cl, 92 ... loop src_loop). That reuses CX as the loop counter, which clobbers the search depth living there, so every recursive call has to re-read the depth back off the stack frame (mov cx, [si + 32]) before decrementing it.
AttoChess walks the source squares by comparing the pointer against the end of the board instead:
src_cont:
inc bp
cmp bp, board_db + 120 ; past the last square?
jnz src_loop
CX is never touched, so it stays the live depth counter for the whole scan. The recursive call site then just does dec cx, and the stack reload of depth is gone entirely.
05Pawn direction folded into the color bit
The original's pawn logic isolates the vector's sign bit, shifts it into alignment with the color bit, XORs against the side-to-move, and branches on parity, which is several instructions of bit-shuffling. AttoChess folds the forward/backward test straight into color bit 5 with a single xor al, dh, and reuses vector parity (odd offset means diagonal) to tell captures from pushes:
pawn:
push ax
xor al, dh ; bit 5 := vector sign XOR side to move
test al, 20h ; forward for the moving color?
pop ax ; POP leaves flags intact
jz vec_cont ; backward: reject
test al, 1 ; odd offset (+/-11, +/-13) = diagonal?
jnz pawn_cont ; diagonal: must capture
xor ah, 30h ; straight (+/-12): invert dest color for the empty test
pawn_cont:
test ah, dl
jz vec_cont
Because the direction test now keys off the side-to-move color rather than an absolute sign, pawns move correctly for both colors from the one code path.
06Piece type held in BX, so the move-table address folds into one lea
Contributed by Peter Ferrie.
The source loop reads a square, masks it down to a piece type, and uses that as an index into the move-vector metadata. Holding that index in AX costs a separate copy into BL and a two-instruction address calculation:
mov al, [bp]
and ax, 07h
mov bl, al ; save piece type
mov si, offset moves_knight - 2 ; base
add si, ax ; + index
Reading straight into BL means the index is already where the slider test later needs it, and the whole address computation collapses into a single lea:
mov bl, [bp]
and bx, 07h ; also zeroes BH
lea si, [bx + moves_knight - 2]
lodsb
cbw ; AH is no longer zeroed by the AND
The original and ax, 07h also cleared AH, so the following add si, ax treated the loaded byte as a 16-bit value. Masking BX leaves AH untouched, so a one-byte cbw has to restore that invariant. Net saving: 2 bytes.
07Test the source after exchanging it into AL
The old routine compares [BP] to CH before clearing AX. Search depth is 0–4, so CH=0. Exchanging the source into AL first and testing that byte preserves the continuing state; an empty source receives an idempotent zero store before the same deliberate self-loop.
; before ; after
cmp [bp], ch xor ax, ax
jz $ xchg al, [bp]
xor ax, ax test al, al
xchg al, [bp] jz $
Encoded saving: one byte.
08Map occupancy and vector parity into PF
The new predicate places destination occupancy in carry, rotates it beside vector parity, and tests the resulting two low bits. Parity is even exactly when occupancy agrees with diagonal/straight movement. POP restores AX without changing PF.
push ax
neg ah
rcl al, 1
test al, 3
pop ax
jpo vec_cont
Because AH remains available for memory undo, XCHG AH,[DI] replaces the BH clone path and removes MOV BH,AH. The destination guard already rejects friendly pieces and borders, so NEG alone sets the occupancy carry. Removing the redundant AND pays for the two-byte -128 search initializer without changing the 272-byte size.
09Make the king value initialize the hidden border
eval_db[7]=2Eh is also init_db[0]. The evaluation lookup is unchanged. In the hidden top border, both the old 09h and new 2Eh block both color masks, and those bytes are outside display, source scanning, and initializer self-feed reads. Saving: one byte.
10Keep the common vector page in BH
The AH-based undo frees BH. Since evaluation data, metadata, and vectors all occupy runtime page 01xx, BH=01h can remain live. Six absolute low-byte pointers move into the unreachable island after RET, permitting a disp8 rather than disp16 LEA:
and bl, 07h
lea si, [byte bx + 53h] ; 8D 77 53
lodsb
mov ah, bh
xchg ax, si
The metadata bytes are E4 EA E9 ED EF ED, selecting full pointers 01E4h, 01EAh, 01E9h, 01EDh, 01EFh, 01EDh for types 2–7. Saving: one byte. This reduction depends on the preceding pawn/undo rewrite.
Verifying the size
Assemble the source, measure the executable, and compare its SHA-256 hash with the published value:
nasm -f bin -w+error -o ATTOCHES.COM AttoChess.asm
wc -c ATTOCHES.COM ; 272 bytes
shasum -a 256 ATTOCHES.COM
The expected SHA-256 is 1e395c1e523f900674add7e86639f248c4658678f08c85b0d6bb2652f5657003. The executable contains the program instructions and table data.
Building and running
AttoChess is written in NASM syntax targeting the 80186.
Assemble with NASM
nasm -f bin -w+error -o ATTOCHES.COM AttoChess.asm
This yields ATTOCHES.COM, a 272-byte DOS executable.
Run under DOSBox
dosbox
Then, at the DOSBox prompt:
mount c: .
c:
ATTOCHES.COM
Any real or emulated 16-bit DOS environment works (DOSBox, PCem, 86Box, or actual hardware), since the program uses only standard DOS int 21h/int 29h calls.
Playing
You play White. The computer plays Black and answers on its own. Enter a move as four characters, source file and rank followed by destination file and rank, for example e2e4. The board redraws after each pair of moves. AttoChess searches four plies deep.
Verification evidence
The current 272-byte build includes a local SMT-LIB query for the shortened pawn predicate and the -128 selection floor. Z3 4.16.0 returned UNSAT.
Unicorn 2.1.4 checks 20 opening inputs, three two-turn sequences, and 100 synthetic positions against a straightforward control with the same search fix. A regression fixture reproduces the previous stop in a losing position and confirms that the current build replies and returns to input.
The previous build's eight queries and differential report remain available as historical evidence on GitHub.
Replay the exact queries and inspect the native proof output on GitHub.
The current query checks local carry and signed-comparison conditions. It does not prove full chess correctness, global byte minimality, or unbounded whole-program equivalence. Historical proofs apply to the preserved previous build.
Prior work
AttoChess builds on the following programs and their approaches to reducing executable size.
LeanChess, Dmitry Shechtman, 2019
LeanChess provides the 288-byte DOS .COM implementation from which AttoChess is derived. Its design uses a padded 0x88 board, a piece encoding that doubles as its own move-generation index, and one recursive routine that both makes a move and finds the best reply. AttoChess is a derivative work and keeps Shechtman's copyright and MIT license intact. For the original implementation, see the LeanChess source.
Toledo Atomchess, Óscar Toledo G., 2015
Toledo Atomchess is a DOS .COM chess program reduced over several revisions to 352 bytes (356 as a bootable sector, 326 in its stripped “HACK” build). Like AttoChess, it omits castling, en passant, and promotion. Source on GitHub.
BootChess, Olivier Poudade, 2015
BootChess implements a chess game in 487 bytes within a 512-byte boot sector. Poudade's page still hosts it.
1K ZX Chess, David Horne, 1982
Implemented a playable chess game in 672 bytes on the Sinclair ZX81 in 1982.
AttoChess, explained
What is the world’s smallest chess engine?
AttoChess is the world’s smallest chess engine: a 272-byte x86 DOS chess program by Nicholas Tanner. It displays its own board, accepts coordinate moves, and calculates replies with a four-ply recursive search. It follows the reduced chess rules of its sizecoding lineage.
What fits in 272 bytes?
Every instruction and table in ATTOCHES.COM. The 272-byte figure is the executable’s file size, not its runtime memory usage. DOS, this website, and the emulator used for browser play are outside that count. You can inspect every executable byte or rebuild the program and verify its size.
Can I play AttoChess in my browser?
Yes. Start a game above to play the original DOS executable in your browser. You play White; AttoChess plays Black. Enter a move such as e2e4, or select a source and destination square. You can also download the 272-byte program and run it under DOSBox.
Why do older articles say 278 or 276 bytes?
Those figures refer to earlier AttoChess versions. The current executable is 272 bytes. The archived builds and their history remain available, and the verification instructions identify the current binary.
Does AttoChess implement every chess rule?
No. AttoChess omits castling, en passant, pawn promotion, full check/checkmate adjudication, and complete move validation. Read the scope and limitations before playing. The verification evidence explains what the current proofs check.
Scope and limitations
AttoChess inherits the following reduced rule set from LeanChess:
- It plays standard piece movement and captures with a real recursive search.
- Like its ancestors at this size, it does not implement castling, en passant, pawn promotion, or full check/checkmate adjudication. The engine keeps playing losing replies; it halts when no move is generated.
- Input is trusted. It expects well-formed coordinates and does not validate against illegal moves the way a full engine would.
These are deliberate trade-offs of this sizecoding lineage. Platforms and rule sets differ across the historical programs above; compare their byte counts with those limits in mind.