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.

The game features a fully functional 16-bit CPU that controls every aspect of your spaceship. The specs for the DCPU-16 have been released and there are several emulators available.

Already, a few communities have been set up around the web to discuss how to program the DCPU-16: the official forum of 0x10c, the 0x10c subreddit, and another dedicated to programming the in-game computer. Already there’s a C-like language that compiles executables for the DCPU and a Game of Life implementation.

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.

72 thoughts on “Getting 12 year olds to learn assembly programming

    1. Or a TTL DCPU, or discrete transistors even.

      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.

  1. This is really cool, I have been messing around with the emulator here:
    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.

    1. HaD.. I criticize Notch a bit and you immediately comment me out? I really don’t think this is appropriate. Having seen Notch’s code on numerous occasions I would know what I am speaking of.

  2. I can’t believe no-one has questioned the accuracy of Notch’s binary arithmetic. Its a 16 bit cpu,

    “a requested sleep of 0x0000 0000 0000 0001 years to last for 0x0001 0000 0000 0000 years.

    It’s now the year 281 474 976 712 644 AD”

    Surely it should be 4096 AD ?

    1. 0×0001 0000 0000 0000 hex is 281,474,976,710,656 decimal, and when you add 1988 (the year they went to sleep) you get the decimal year quoted.

      Or in other words, you aren’t smarter than a fifth grader.

    2. 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.

  3. “joys of assembly programming on a 1980s-era computer”

    Having done this there is NO JOY in doing so. I even did assembly at university, again, NO JOY.

    Hopefully after this spectacular flop people will stop preceeding his name with “mastermind” or “guru” or other unaccrediated made-up words.

    Seriously, I don’t need to build a wheel out of rock with a hammer to appreciate how a car works.

      1. 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.

      2. 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.

    1. BTW – my standing challenge for anyone who says they ‘understand the wheel’ is to explain the network of forces that make a bicycle wheel work. It’s a more complicated than most people think.

  4. WTG HaD…

    Being a Minecraft fan I was already aware of this news, but your write up gave me a bit of new perspective on the new game\sim.

    Piqued my interest by an additional ~%35 or so…


  5. 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?

    1. I think most people misunderstand why Minecraft is so popular.

      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.

      1. 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.

        #2 is what really worries me.

      2. That’s what’s great about minecraft… it means different things to different people.

        For some the allure may be ‘carving out their own place with their own hands’, but for me it’s the mods and Mojang’s acceptance (nay, encouragement) of them.

        For me… at this point… Minecraft is all about IndustrialCraft2, BuildCraft and RedPower and making a ‘factory’ to manage all of my harvested resources…

        …I like minecraft because it allows me to let my inner engineer out of it’s cage for a bit to run around.

  6. 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.

  7. 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.

  8. 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?

    1. 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.

      Garbage collection? Sure.. mark-and-sweep, reference counting, hard/soft reference counting, or a blend of some/all the above? In all cases, it’s a simple matter of mixing graph theory, context switching, and your OS’s memory management policies.

      Those are big chunks for beginners.

      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.

    2. 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.

  9. 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.”

  10. 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

  11. 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.

  12. @ Mmarrero …

    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.

  13. I found this 16bit division code I used in a MS-DOS Voice Mail app I wrote in ’93 :-

    DAX: DW 0
    DDX: DW 0
    DAXR: DW 0
    DDXR: DW 0

    ; WORDDIV – Divides DX:AX by BX, returns result in DX:AX


    WD_L:CMP DX,BX ;You mustn’t divide if the high
    JB WD_CONT ;word is greater than divisor
    SUB DX,BX ;So just carry on subtracting
    JMP WD_L ;until you got a Modulo.
    DIV BX ;Divide
    MOV WORD PTR [DAXR],AX ;Store in AX

    MOV AX,WORD PTR [DDX] ;Divide just the High word
    MOV DX,0
    DIV BX

    ADD WORD PTR [DDXR],AX ;and add it to the result

  14. DAX: DW 0
    DDX: DW 0
    DAXR: DW 0
    DDXR: DW 0

    ; WORDDIV – Divides DX:AX by BX, returns result in DX:AX


    WD_L:CMP DX,BX ;You mustn’t divide if the high
    JB WD_CONT ;word is greater than divisor
    SUB DX,BX ;So just carry on subtracting
    JMP WD_L ;until you got a Modulo.
    DIV BX ;Divide
    MOV WORD PTR [DAXR],AX ;Store in AX

    MOV AX,WORD PTR [DDX] ;Divide just the High word
    MOV DX,0
    DIV BX

    ADD WORD PTR [DDXR],AX ;and add it to the result

  15. I think the DCPU will speak to the geek in us all…

    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.

  16. ; Assembler test for DCPU
    ; by Markus Persson
    ; BLuRry: Reduced footprint by removing extra crud and introducing self-modifying code [EVIL!] These tricks will come in handy if space is a premium!

    set i, 0

    set a, [data+i]
    ife a, 0
    set PC, end
    ifg a, 0xff
    set PC, setcolor
    bor a, b
    set [0x8000+i], a
    add i, 1
    set PC, nextchar

    set b, a
    shl b, 8
    add i, 1
    sub [0x0e],1
    set PC, nextchar

    dat 0x170, “Hello “, 0x2e1, “Hackaday”, 0x170, “, how are you?”

  17. aha! I could use an avr as a ALU for multiplication/division! (its that or a 4G lookup table) (x2)

    hmmm…. 11 alu instuctions….
    6 ports for data in/out 4 bits for operation selection…
    52 io bits…..might have to mux something…

  18. I remember being six years old messing with an old 16-bit computer. But unlike others, I wasn’t using languages like BASIC. I was doing things in pure Assembly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s