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.

16 comments

Alex Eames (RasPi.TV) avatar

That’s incredible. There’s some amazingly talented people out there.

Robin avatar

Although I agree about the talented people, and this is really not easy!!! Still it’s not much different to what people used to do on the C64, Amiga, MSX etc etc…

Eir avatar

Are you serious?!? Do what on the C64 and Amiga? How many people do you know that created a chess game for the C64 or the Amiga? Get lost pal, this project requires A LOT of talent and work. She said “first year project”… If this is their first year project, I wonder what they’ll do next…

glenn avatar

Hey! Pal! The Commodore 64 was a faboulous machine, it got kids interested in programming! That is what the Pi was for! and… HEY, I wrote a chess program in BASIC for the commodore 64 and the APPLE II too! (I used MIN-MAX and lots of arrays) ((NOT EASY on 48 K!)

glenn avatar

They were excellent for getting people to learn to program.

tzj avatar

This could be used as a bare metal os to control gpio, but I’m not sure if they included gpio output too, or whether it can only do simple on/off functions.

diereinegier avatar

How very refreshing!

In most commercial software projects you would be crucified for the design decisions made here. But hey – what an accomplishment!

Ralph Corderoy avatar

Ah, I wondered what they did about USB; they use the GPIO pins for input.

Gael avatar

No OS is amazing! Although it reminds me of the NES where the entire game was on circuit board without an OS. Now consoles all have some type of OS incorporated with them.

Nathanael Smith avatar

There is a Pico-Chess program which connects the Pi to a chess board with sensors in it.

The cheap / minimal nature of the Pi suits it to such dedicated single application use – so why use an OS if you can get by without one. I also wonder if that allows for performance increases.

Hats off.

y0g1337h avatar

OMG… This is awesome. Hard work + talent + skill :)

AndyD avatar

Very impressive!

steve avatar

Super! Absolutely super.

For those arguing further up the page about C64 it should be remembered that back in the day there was a chess programme written for the ZX81 in assembler in 1K.

Stop the arguing! :) The kids have done good, be pleased for them.

brox avatar

Not impressed. No AI and 15k lines of asm code? Guys, you definitely could learn a trick or two of old good demoscene days…

tom avatar

If you actually look at the code, you will see that their language has no support for arrays.

12 thousand lines is used as arrays. Only 3 thousand is for the game code, and given they detect possible moves, checkmate and stalemate that’s pretty damn impressive.

Roger Smith avatar

Very amazing, especially because it’s in assembly.

Comments are closed