MENU
Systems & ToolsArchive

Tic Tac Toe

Repository

This project implements Tic Tac Toe in two x86 Assembly targets: a 16-bit DOS version using BIOS interrupts for I/O, and a 64-bit Linux version using raw syscalls. Writing both versions side by side required working directly with registers, the call stack, and terminal control, with no standard library or runtime.

#Assembly

Dual-Architecture Implementation

The DOS version uses INT 10h for video control and INT 21h for character I/O. The Linux version replaces those with SYSCALL 1 (sys_write) and SYSCALL 0 (sys_read). Comparing the two showed the difference between 16-bit real-mode addressing and 64-bit protected-mode execution at the instruction level.

Win Detection Logic

The CHECK routine evaluates all eight win conditions: three rows, three columns, and two diagonals. Each condition loads three board cell values into registers, compares them in sequence, and uses JNZ (Jump if Not Zero) to skip to the next condition on a mismatch. When all three cells match, the DONE flag is set to 1 and execution jumps to the board display routine.

Terminal UI and Input Validation

The 64-bit Linux version uses ANSI escape sequences to clear the screen and reposition the cursor before each redraw, producing a stable terminal UI without a curses library. The TAKEN routine catches attempts to overwrite an occupied cell, decrements the move counter, displays an error message via INT 21h, waits for a keypress, clears the message, and returns to the input prompt.

Low-Level Challenges

Capturing single-character input on Linux without requiring Enter required switching the terminal to raw mode by manipulating the termios structure via ioctl system calls. Managing the stack frame manually for each procedure call, and computing 64-bit address offsets by hand, was the core technical work of the Linux port.

Video Demonstration

External Media Required

This video requires third-party cookies from YouTube to be displayed. Accepting will enable all external media across the site.