A fully functional chess engine implemented in MIPS assembly language using only basic MIPS instructions (add, sub, addi, lw, sw, lb, sb, beq, bne, slt, sll, srl, j, jal, jr, syscall, etc.).
- Complete chess board representation
- Coordinate move input (e2-e4, g1-f3, etc.)
- Move parsing and validation
- Castling, en passant, and promotion support
- Check and checkmate detection
- Basic but functional AI opponent
- Plays as Black (computer) vs White (human)
- Standard chess rules implementation for all pieces
- A MIPS simulator such as SPIM, QtSpim, or MARS
- Terminal access for text input/output
- Install a MIPS simulator (SPIM example shown below).
- Run the engine:
spim -file chess_engine.asm- Enter moves in coordinate notation (e.g.,
e2-e4).
For a longer sample session, see EXAMPLES.md.
You can run this chess engine using SPIM (MIPS Assembler and Runtime Simulator):
spim -file chess_engine.asmThe engine runs in text-only mode with no visual board display. You interact with the engine through text-based input and output only.
Enter moves in coordinate format (from-to) to match the engine output:
e2-e4- Move a piece from e2 to e4g1-f3- Move the knight from g1 to f3f1-b5- Move the bishop from f1 to b5e1-g1- Castle kingsidee1-c1- Castle queenside
Note: The engine validates that the piece at the source square can legally move to the destination square.
$ spim -file chess_engine.asm
MIPS Chess Engine
==================
White's move: e2-e4
Black's move: Computer plays: e7-e5
White's move: d2-d4
Black's move: Computer plays: d7-d5
White's move: c2-c3
Black's move: Computer plays: c7-c5
White's move: [continue playing...]
The game proceeds with text-based input/output only. No visual board is displayed - you track the game state mentally or on a physical board.
chess_engine.asm: MIPS chess engine implementationtest_chess.sh: Static checks and usage hintsEXAMPLES.md: Extended usage examples
- 8x8 board stored as a 64-byte array in memory
- Each square contains a piece code (0-12)
- 0 = empty
- 1-6 = White pieces (Pawn, Knight, Bishop, Rook, Queen, King)
- 7-12 = Black pieces (Pawn, Knight, Bishop, Rook, Queen, King)
The computer uses a simple evaluation function based on:
- Piece hierarchy (prefers higher-value pieces)
- Captures (small bonus)
- Greedy algorithm (picks highest value move available)
This implementation uses only basic MIPS instructions as specified:
- Arithmetic:
add,sub,addi - Logic:
and,andi,or,ori - Shift:
sll,srl - Memory:
lw,lh,lb,lbu,sw,sh,sb - Comparison:
slt,slti - Branch:
beq,bne - Jump:
j,jal,jr - System:
syscall
Note: The code uses pseudo-instructions like blt, bgt, bge, ble for readability. These are automatically expanded by SPIM into basic instructions (slt followed by beq/bne). All pseudo-instructions can be manually expanded if needed for assemblers that don't support them.
- AI is basic (material-based evaluation only)
- No visual board display
A test script is provided:
./test_chess.shThis will verify the assembly syntax and provide instructions for manual testing.
- The engine parses coordinate input for pawn and piece moves
- Move validation enforces legal moves including special rules
- The AI evaluates moves based on captures and piece advancement
- All game state is maintained in MIPS memory (data segment)
- No external libraries or advanced features are used
Possible improvements:
- Improved AI with positional evaluation
- Move history and undo functionality
- Save/load game state
- Better move notation support
Created as a demonstration of a functional chess engine using only basic MIPS assembly instructions.