Getting 12 year olds to learn assembly programming

[notch], the mastermind behind Minecraft, is working on a new game. It’s called 0x10c (pronounced ‘trillek’, we think) and promises to teach an entire new generation the joys of assembly programming on a 1980s-era computer.

The setup for the game is nerdy/awesome enough to make [Douglas Adams] blush; a ‘deep sleep core’ was invented in 1988 that attached to the 16-bit computers of the day. This core was big endian, where the DCPU-16 (the computer in the game) was little endian. What was supposed to be a one-year hibernation turned into a 281 Trillion year coma, the Universe is dying, and everyone from 1988 is just waking up.

We know this isn’t a usual Hackaday post. Despite this, we’re fairly certain a good percentage of our readership will be programming a DCPU-16 in the next year. It just might be time to crack the books and learn how to build a compiler and OS. The dragon book (Compilers Principles, Techniques, and Tools, Aho, Sethi, Ullman, 1985) is very good, and [Andy Tanenbaum]’s Operating Systems Design and Implementation is how [Linus Torvalds] got his start.

One more thing: we’re going to be running a contest for the best physical implementation of the DCPU-16 in a few months. We’ll wait until the in-game hardware is nailed down, along with any peripherals [notch] plans to add. Right now the prizes are some HaD schwag, but that may change. Further info with updates pending, but you’re free to start working now.

Whatever, a three cycle 32-bit divide will be very big (combinatorial) or hard (iterative with tables?), or both. Same would be true for the multiply, though less extreme.

The instruction timings look a bit wonky and ill-suited to a hardware implementation. I would probably tackle it by microcoding something more basic with about 10x higher clock frequency, but it would bother me to know it would be busy waiting most of its life.

This is really cool, I have been messing around with the emulator here: http://denull.ru/dcpu/dcpu.htm
and started to learn more advanced assembly than I know for it. However, I am pretty sure once the game comes out there are going to be good C compilers for the DCPU-16 that all the real in-game programs will be written in C. What I want to see is how the in game space ship will be controlled by the computer using some sort of I/O, that is the interesting part.

Actually, since it’s a 16-bit CPU, shouldn’t the endian only affect the bytes within each 16 bit word? If so, 0x0000 0x0000 0x0000 0x0001 would just become 0x0000 0x0000 0x0000 0x0100 if the endian was screwed up… i.e. 256. (Why would the 0x0001 shift 48 bits? The documentation of the CPU doesn’t mention anything about how 16-bit words are grouped into 64-bits for any reason.) So… seems like there is certainly something amiss.

The real life Apollo Guidance Computer has similar specs and was actually used to send people to the moon. They’re both 16 bit processors, but the AGC has only 1 register as opposed to 8 and also fewer instructions. There is even a complete open source emulator which handles not only the CPU, but all the peripherals.

I think it would have been cool if Notch integrated yaAGC into his game instead.

I cant tell you how many times I try to relate this to my colleagues. Understanding the underlying hardware is a must for producing competent code. Otherwise, you get people storing IP addresses in databases as VARCHAR 128s and wondering why queries take so long to process.

Storing as a VARCHAR 128 would be really stupid, since for IP4 you would only need to store a max of 15 characters, VARCHAR 15 would do fine and and would take up a max of 16 bytes of storage (1 extra byte for varchar overhead). Of course there is a way to convert a IP4 address to an unsigned int (MySQL: INET_ATON PHP: ip2long) for better indexing.

I heard about this a few days back. It’s great to know that there’s now basic documentation and emulators. I just got through writing a simple text parser.

However, does anyone else feel like this game would largely exclude the current Minecraft fan-base from playing? Let’s be honest, most people who play Minecraft are not the people building adders in it.

I mean, they’d be getting so little out of it if they’ve never programmed anything in assembly. I doubt they’ll all want to learn. They’d probably be better off playing Minecraft anyway. Is this, by design, a game only for programmers?

My feeling on it is that Minecraft touches something very essential in us, the desire to carve out a place for ourselves with our bare hands, to build a house and find food and make a life in the ‘wilderness’. Those things are core to what we needed to survive in the not too distant past, and things that we have very little access to in most of the developed world today.

OTOH, I think it could be cool. So called ‘hacking’ games have proved popular in the past, I recall a web based puzzle game that included a minicomputer you used to circumvent traps, and Fallout 3’s hacking password system was kinda fun, but a bit far from what Notch is making here.

I sincerely hope that the coding part of the game is secondary to a survival aspect, in which you get to see the gameworld, not just through the ‘eyes’ of the CPU. Having to program to solve clear and present problems for the crew would be fun.

I don’t know if I came off the wrong way or if I just didn’t understand your reply, but I do fully understand the allure of Minecraft. I don’t think anyone expects the game to be played “through the eyes of the computer”. That sounds awful.

Anyway, “having to program to solve clear and present problems for the crew” is EXACTLY why I think some people will be disappointed.

I feel two ways about this:
1) I can’t wait for this game to come out.
2) I wonder if there will be enough people playing to keep this game going.

Given the nature of the instruction set, this thing looks like a natural Forth machine.

The advantage of Forth (for those who don’t already know it) is that it’s a stack-based RPN language. It doesn’t require a compiler because its command syntax is identical to its syntax tree. The code is executable as you type it in. Interpreters are small (I think the smallest one is like 4k) and get about as close to programming bare metal as any language can.

Leraning and programming in z80, 6502 and 6809 machine code and assembler was a highly enjoyable experience for me back in the early eighties. I am looking forward to this game giving me a bit of a nostalic high, but more importantly, maybe giving my kids the chance to experience the same. What with this and the RasPi 2012 is turning into a good year.

There are 2 problems with this…
1) learning assembly is useless in todays computing for the vast majority except as a novelty, most people working in embedded even rarely use it
2) it isn’t going to teach many 12 year olds assembly because it is too obscure to get them interested in the first place

The general idea sounds great but why not make it more accessible rather than aiming at such a small niche?

Assembly is valuable because it strips away about twelve layers of abstraction that are built into all popular/modern programming languages.

Object oriented programming? Sure, makes perfect sense if you know the correlation between abstract datatypes and function-block programming, the intricacies of data typing and scope encapsulation, and enough computation theory to see the correlation between an object oriented program and a network of theoretical register machines.

Playing with assembler gives you a chance to see basic concepts like data representation and argument passing in action. You get to see why GOTO is such a powerful/dangerous thing to use indiscriminately. You get a firsthand understanding of ‘the stack’ and ‘the heap’.

Seeing the basic operations gives you a foundation for understanding what omdern programming langauges actually do.

Once you’ve got that, /then/ you can move on to multicore/multiple-processing-unit CPU architectures, microcode generation, branch prediction, pipeline latency, and all the stuff that makes compilers really earn their keep.

Knowing how your C code will convert into assembler is still very relevant. Recently I had to spend some serious effort speeding up an Arduino project, and that would have been impossible without some assembly experience and an understanding of why some methods will be faster than others.
…and why some methods are MUCH faster than others…
If you’re having problems, the LST file is a powerful tool to understand what’s going on in a very detailed way. …and I work with people who can’t even read the thing! It’s an essential skill for an embedded programmer, and a highly informative exercise for any other programmer.

Games are fun. While you’re at it, why not learn more about assembly? Here’s a free e-book that teaches assembly and CS concepts, Programming from the Ground Up: “… an introductory book to programming and computer science using assembly language. It assumes the reader has never programmed before, and introduces the concepts of variables, functions, and flow control.”

I think it’s not a good asm language for educational purposes.
– No signed integers
– No carry operations: rotate, add/sub, etc.
– Use “overflow” flag for carry conditions??
– JMP, RET: ok, but must be assembler macro
– [Mem],[Mem] is expensive, invalid in many CPUs
– MUL 2+ cicles, DIV only 3+ cycles? Unicorns too?
– IFx is a nice idea, but only useful in loops

I think HaD readers are being blinded by their own understanding of technology.

Think of all the people who bought and play Minecraft. Minecraft is an amazingly simple game. You get blocks which you put on other blocks. I can explain the concept of a brick block, a stone block, a cobblestone block to a three year old and have him able to build something resembling a structure in an hour or so. That is why Minecraft is so immensely popular. It’s easy to get into and learn and you can play it even if you don’t know but a fraction of the crafting recipes. All of it deals in real-world constants with almost zero abstractions involved outside of redstone. I just can’t picture even a fraction of this playerbase understanding or being interested in computing at this low of a level.

I want this to succeed, but I’m predicting a monumental failure in the making. I can’t even think of any Computer Science majors that I know who would even bother with something on this low of a level because most of them have only worked with high-level languages all of their lives. This is a game specifically aimed at hobbyists, the autistic, and engineers (none of which are exclusive to one another). People who do not need virtual 16-bit computers to play around with because they likely have microcontrollers of their own.

This isn’t going to stop HaD from controlling doors, turning on lights, posting on twitter, or delivering web-updates with the DCPU-16. Which makes me glad as I feel the tiny niche group of hackers and hobbyists may be the only people who ever end up playing this game.

1. 2’s complement Add and subtract are sign agnostic.
2. Carry/Overflow weirdness is actually very typical of mid 70’s minicomputers.
3. Some of those minicomputers had hardware add on boards; the HP2100A (the one I encountered via my Dad’s lab as a kid) had floating point in hardware as an option. The basic computer might not do 3 cycle multiply, but the add on card could.

The superfast mul/div is actually not such a stretch when you consider that the base clock of the computer is 170 kHz, consistent with magnetic core RAM, and even in 1975 pure silicon could be a lot faster than that.

I personally get great pleasure coding in LUA for the ComputerCraft addon for Minecraft. So having something else to do in a game that by definition, takes us away from the mundane, is great! Sometimes, solving complex problems with code is what any game needs. Nothing is more frustrating than trying to figure out someone else’s solution within a confined bit of code. So the geek in us all would rather just code our own solution, thereby making the solution uniquely ours while still keeping the game enjoyable and playable.