Wednesday, July 3, 2013

Chess. Bare metal assembly language chess.

Pootling around the Raspberry Pi forums late last night, I found something that rightfully shouldn’t exist. It’s a two-player chess game for the Pi – nothing so unusual there – written in assembly language, with no OS. Which is highly unusual.

Xu Ji, one of the three Imperial College students who wrote this piece of…bravura showing-off, had this to say in the forums:

My two friends and myself have successfully written a chess game for the Pi. It’s a graphical game with a colourful chess board, so we interface with the GPU and whatnot, and we do it all in assembly without an OS running on it.

We actually wrote the assembler too (in fact this was the actual assignment for the project), but it was based on the ARM7 assembler so it’s probably compatible with official assemblers (although we have not tested this).

It is due to the fact that we ourselves wrote the assembler (in C) and we only had 2 weeks for this that we only support a limited number of instructions in (our version of) assembly language. For example we are forced to use labels for variable names.

The game is written to replace kernel.img inside the OS and is about 15 thousand lines.

We thought some people may find the chess game interesting as a project, and it may inspire others to try writing games in assembly, so we are posting the link to the repo here:

https://github.com/xu-ji/assembly_chess/

Given our restrictive language we didn’t think we’d make it, but somehow it actually works…

 

It really does, too. Here are Xu Ji, Bora Mollamustafaoglu and Gun Pinyo, giving a storming demo. We hope you got top marks for this, guys: you totally deserve it.

If you’d like to learn more about assembly language, we highly recommend that you get your Pi out and start working through Baking Pi, a course developed last year by Alex Chadwick at the University of Cambridge, which will take you from knowing nothing at all to being able to build a simple operating system on the Pi. You can read more about Baking Pi here.

No comments:

Post a Comment