Tic Tac Toe in… x86 assembly!

ttt

What do (hopefully) future computer engineers do when they are trapped in a huge typhoon in the midst of summer?

How about… Tic Tac Toe in x86 assembly complete with a primitive (yet unbeatable =P) minimax AI?

ttt.asm

actually, I cheated, kind of. I wrote a C version first (took me all of 1 hour) before manually “compiling” it (took me… quite a few days) =P

ttt.c

If you want to give it a try, just use the C version (won’t work with Visual Studio, though, since I am using GNU extensions for specifying calling convention). The C version should work with both Windows and Linux (though I only tested it on Linux), and I wouldn’t be surprised if it’s more stable than the asm version. The C version can be compiled the way you compile any other C program.

On the other hand, feel free to hack around with the asm version. It won’t work on Windows without modifications, though (Windows append underscores before symbols, and I heard they use the Pascal calling convention for the standard library, or at least the Win32 API). Every function in the asm function is directly equivalent to the function with the same name in the C version, and follow the standard x86 calling convention to the letter (that’s the intention anyways =P), so they can actually be linked together using some functions from the C version, and some from the asm version (that’s actually how I tested each module individually). To assemble it, run “nasm -f elf ttt.asm && gcc -o ttt ttt.o”. The GCC step is necessary because it needs to be linked to the C standard library.

Have fun! (don’t ever swear you will beat it before you go to bed or something… you won’t =P unless there’s a bug in my implementation)

3 thoughts on “Tic Tac Toe in… x86 assembly!”

  1. apparentli i’m the first to comment, twice

    anywho, i am jealous of ur programming skills. good job=D now pls make a more fun game for us to play in math265 class

  2. well, referring to the last blog update and the comments following it, we concluded that i had a life and someone else did not. That explains why u were the first to post twice =).

    Thank you, please come again in 10 years.

Comments are closed.