Close
Report Comment to a Moderator Our Moderators review all comments for abusive and offensive language, and ensure comments are from Verified Users only.
Please report a comment only if you feel it requires our urgent attention.
I understand, report it. Cancel

Machine Code is for Kids!

Wed 30 Mar 2011 7:00am GMT / 3:00am EDT / 12:00am PDT

Dylan Cuthbert on why machine code is perfect for kids to learn programming

GamesIndustry.biz is proud to present the best writing from #AltDevBlogADay, a blog populated by game developers who write about the creation and business of games and related subjects.

Here, Dylan Cuthbert of Q Games discusses the best language to learn programming, his history with BASIC and why he thinks old machine code is a perfect fit for children.

There was some talk on twitter a few weeks back about "I want to teach my 10 year old to programme, what should I start him on?", and a number of people responded with common student-like answers such as "flash script", "java", "lua", "C", no! "C++", no! "C goddammit", etc etc, and I started to have a think about this problem in some detail.

First some history, I learnt to program in BASIC starting from the age of about 10 (1982), by copying in listings from magazines at a friend's house on a ZX Spectrum he had got from an uncle who worked in the Sinclair factory, no less. My friend and I would take turns copying in the text, with one of us reading it out while the other typed, and this is how I learnt to type relatively quickly. What is amusing is that because we were so young we didn't know the proper names for the various symbols in the code, for years afterwards I would still call quotations marks "those things" as a result. But anyway I digress, in many ways the old BASICs with line numbers and older forms of machine code were perfect languages for learning in and this is article is my attempt to explain why.

Abstract Thought is an Adult Skill

It's my view that for a child to be able to learn quickly to code he/she needs a language with the minimum amount of abstraction possible. Have a think about that for a bit. Abstract thought is a skill that gradually grows as you get older, but when you are a kid your brain is wired to take everything at face value; it's a survival instinct that helps you place complete trust in your parents and other adults and as you get older the opposite becomes a survival instinct and abstract thought develops (e.g. the concept that Father Christmas perhaps isn't really visiting you via the chimney every year). Anyone who has or deals with children knows that what you tell them is believed pretty much absolutely.

The old-school BASICS were imperative languages and fairly crap, but one important feature they had was a very low level of abstraction.

As an example, this means that even the relatively simple C concept of '**' meaning "pointer to a pointer" is hard to visualise for young children. They might eventually get to the meaning of it in their own terms but the more abstract concepts there are, the harder they will find it to move forwards, and if guided correctly to avoid these abstraction pitfalls children can move forward at a faster rate and learn much more. I really think the trick is to steer clear of the extraneous abstraction we, as adults, cope with so easily and take for granted.

The old-school BASICS with line numbers were imperative languages and fairly crap when compared to any other language, but one important feature they had was a very low level of abstraction. Any school kid can type 10 PRINT "HELLO MUM!" and then 20 GOTO 10 and understand exactly what it does – even my mum can understand! – the equivalent in (almost) any other language requires many, many abstract concepts.

To illustrate this, here is what it looks like in C, one of the "simplest" languages:

1

What's so hard about that you probably ask yourself? That should be a total doddle for a kid to learn! But let's take it step by step (actually, let's just take the first line!) and you'll understand why a child would have trouble, the questions would probably go something like this:

  • 1. What's that funny # mark?
  • 2. What is "include"
  • 3. What is "stdio.h" and what are the funny arrow symbols for?

Just to begin with, those three questions require days of teaching and I leave the rest as an exercise for the reader (and it is an interesting exercise to sometimes remove the blindfolds caused by familiarity) but the list is long. Of course the standard adult answer to these "where do babies come from?" kinds of questions from children is something to divert the question or leave the explanation for a later date. But this is exactly what you don't want if you are trying to teach children. You don't want the child using concepts because they have been told to use them "because that's the way it is", you want them to use the concepts because they understand them.

"Let us praise machine code O'Lord, ooh you are so big, so absolutely huge. Gosh we're all really impressed down here, I can tell you. Forgive us O'machine code for this our dreadful toadying and barefaced flattery, but you are so strong and, well, just so... super." – Monty Python on machine code.

...is generally the opinion of people who haven't touched or worked with machine code to any extent. Machine code is seen as an untouchable omnipresent super-being that is better to simply be in awe of than to have to deal with it. For those of us who have made entire games on CPUs with only three registers, typing with our nose and both hands tied behind our backs (on a good day), well... it's as easy as pie (preferably a chocolate one as you will see later).

2

Dylan, hands tied to pockets, aged 19, a rare glimpse inside Nintendo EAD during the very early stages of StarFox.

I'm not saying it is the quickest vehicle to take you where you want to go, but conceptually it is non-abstract pure logic and flow, and surprisingly easy to understand. It also gives you the ultimate flexibility and the age-old adage "computers only do what you tell them to do" actually becomes slightly believable. (Note: If you are a programmer, you owe it to yourself to make machine code your bitch, you are actually the omnipotent super-being and machine code honours you with its humble service!)

So back to BASICs (sorry!), BASIC is pretty much just assembler/machine code that has been extruded slightly, given a couple of boosts for ease of use (primarily auto-allocated variables, string manipulation and math notation), and expanded lexically into something more readable. The line numbers are equivalent to memory locations for example and the flow of the program can be directly visualised by simply stepping through the instructions.

Another key important feature of BASIC is that it is bloody slow (and if it isn't you should force it to be by giving your kid an old ZX Spectrum to learn on). This inherent crap slowness is great for kids because it encourages them to explore faster alternatives, and the alternative that is most equivalent to BASIC is actually machine code. Sounds weird doesn't it? I mean, isn't machine code meant to be for hardcore programmers and their ilk and impossible to learn by anyone other than hackers from northern Europe? Well no! For a child machine code is actually the next easiest thing to learn, as thousands of whizz-kids found out in the 1980s.

If you are a programmer, you owe it to yourself to make machine code your bitch.

Poking Digits Into Memory

The system is simple, you have a limited set of instructions, a limited set of registers, and memory (I remember in old machine code books this used to be illustrated by an open hand with a register per finger, that you would then POKE into memory... I can't remember how the memory was portrayed, maybe it was a giant chocolate cake... mmm poking fingers into chocolate cake, well that already sounds FUN!).

Complexity For The Sake Of Complexity

After having this article proofread by a certain machine code madman who goes by the name of Jaymin Kessler, he initially said, "but will kids really understand register spilling, stack frames, register allocation?". He instantly brought in a ton of abstract terminology that was invented primarily for compilers of higher level abstract languages. These are all pre-conceived notions that aren't needed to learn assembler at all – there's no need to even just have one stack in assembler, why not have three? (wait.. C doesn't let you do that so how? oh!) And you might not even use a stack frame at all, it's up to you; there is nothing abstract and pre-decided in machine code apart from the absolutes: memory, registers and instructions. What you do and where you take it from there is for the child's imagination. For example, quite often the stack related instructions in old 8-bit CPUs were used for fast clearing or setting memory, this flexibility is very pure yet easy to understand because it isn't at all abstract.

Twelve Small Steps To Learn Machine Code

To round things up here's a simple list of concepts that a child should find fairly easy to learn (I did):

  • 1. Binary – show them how binary values can be visualized by using a monochrome bitmap screen and writing values into it. Show how 8 values can form an 8x8 grid and be "seen" as the letter "A". Ask them to calculate the 8 values to display the first letter in their name.
  • 2. Hexadecimal – 8 bit is fine to begin with and then show them fun things such as calculating the decimal value of B00B.
  • 3. Registers – visualise them as your fingers, limited in number.
  • 4. Memory – a neatly sliced cake or the keys on a piano are good visual aids.
  • 5. Instructions for simple math combined with loading and storing. LOAD/STORE/ADD equivalents.
  • 6. Looping and the concept of counters.
  • 7. Binary math – show them how "shifting right" divides by two and make sure they understand why. Explain XOR/AND/OR and how they can used visually for inversing, blending and masking.
  • 8. Explain calling and the concept of return (GOSUB/RETURN should be a concept they are already familiar with from BASIC), and teach them register preservation (a slightly abstract concept but one that is quickly learnt).
  • 9. Teach how a single stack works (perhaps combined with 8.) and the concept of push/pop LIFO for temporary storage (in the old-school 8-bit sense).
  • 10. Concepts of data structure (relative access methods) and arrays of repeated structure.
  • 11. Above all show them how much faster it all runs compared to BASIC, this is the hook!
  • 12. Then simply expand and combine all of the above.

BUT BUT...

After writing this and extolling the virtues of BASIC and machine code there is an important saddening point I really have to add and that is that we now live in a day and age where machine code has been so far hidden from us it is actually difficult to find a good platform to give a 10 year old to start on. BASIC doesn't exist anymore either, not as far as I'm aware anyway, so my question to the readership is, given the pre-requisite of "little to no abstraction", do you know of a good replacement for the old BASIC -> Assembler path of learning for pre-teens that produced so many amazing programmers during the 80s and very early 90s?

Please Do Note However: Throughout this article when I am talking about machine code, I am talking about real chips, such as Z80, 6502, 68000, MIPS, ARM, etc, and not about the bastard-child we call x86 architecture or any of its variants. Don't let your children anywhere near that pile of stinking bat poo.

27 Comments

Roger Godfrey
Agile Project Manager

3 0 0.0
Hey, X86 is not that hard. :)

Posted:3 years ago

#1

Roger Godfrey
Agile Project Manager

3 0 0.0
Excellent article BTW. When my 2 year old daughter is a little older I am very tempted to give her my old Spectrum and a copy of Programming The Z80 by Rodney Zaks. :)

Not sure where I would find a tape recorder in this day and age though.

Doing this has to be more fun for kids than ICT: http://www.gamesindustry.biz/articles/20...

Posted:3 years ago

#2

Jaymin Kessler
Programmer

1 0 0.0
Roger: its not hard, its just an ugly abomination that no one should have to be exposed to. There are lots of better ISAs out there

Posted:3 years ago

#3
Roger - you can just plug the audio leads into your PC and sample/play-back to save load. No stretchy tape problems either!

Posted:3 years ago

#4

Curt Sampson
Sofware Developer

596 360 0.6
The problem here, of course, is that the fellow's picking from a woefully small space of languages, ignoring those designed specifically for children (Logo, Smalltalk) and others not so specifically designed but that have been proven to work very well (Scheme).

There's been huge amounts of work done on teaching children to program, going far beyond, "Well, I sat down and thought about it for a bit." Start with the TeachScheme! project.

Posted:3 years ago

#5
Actually if you look at the original article's comment section we talk about Logo, a language I also learnt a bit in before moving quickly to BASIC. We also talk about other simple non-abstract languages like that.

Also in the that comments section I point out that my assertion about abstraction not being suitable for young kids comes from one of Richard Dawkins books on evolution where he discusses this kind of thing in detail. That's where it clicked actually and this article has been brewing for many years.

Scheme has been "Proven to work very well" you say - well I sure can't seem to find any proof of pre-teen wunderkinds programming in scheme? I mean, I can find thousands of examples in the games industry of people who followed the path described above and were programming in assembler before they turned 13. The proof's in the chocolate cake. I'm sure people can learn Scheme once they get to an older age and abstract thought becomes a part of the process. Also, the learning of Scheme really has little or no application to games development (we're talking reality here, not fantasy) but machine code and knowing what is going on under the hood will *definitely* benefit you.

(oh, and less looking down your nose if you please Mr Curt "teh Attitude" Sampson ;-), it's a bit rude to suggest that someone who has put a fair bit of effort into an article just "sat down and thought about it for a bit", well thanks man for belittling my effort!! )

Posted:3 years ago

#6

Tom Keresztes
Programmer

682 335 0.5
@Curt,

When i was 13 i was not interested in Logo because games and demos were written in something else. I was not interested in learning a toy, which has no flashy examples.

Posted:3 years ago

#7

James Boulton
Tools & Tech Coder

133 171 1.3
Calling assembler an "ugly abomination that no one should have to be exposed to" is a bit harsh! Unless you understand how a machine works at it's lowest level, you will never be as competent a coder as you could be, and will certainly be poorly prepared for hardcore code optimisation.

These days assembler isn't much fun, I'll grant you that. Trying to hand optimise assembly code for a muti-stage execution pipeline with multiple cores and multiple memory caches is about as fun as having your teeth pulled out. But unless you understand this, you are missing a fundamental foundation of programming.

I first started programming 68000 assembly when I was about 10 or 11 and still love the language today for it's simplicity and elegance, although there's not much call for it any more. Those were the days when you really could optimise code logically by counting cycles.

The days of coding any large pieces of code in assembler may be long gone, but it really is an essential skill for anyone who wants to be a competent coder. Teach it I say!

Although I do agree x86 is an ugly abomination that no one should have to be exposed to. :o)

Posted:3 years ago

#8
I was great experience programming in x86 assembly and I tried Z80 assembly too just for fun. I had knowledge of Pascal and BASIC at that point of time, but I must agree with all that is said in this article... Machine code is great to start with!

Posted:3 years ago

#9

Kiersten Samwell
Community Manager

1 0 0.0
For our younger players (E10 Game) I recommend a FREE book about programming with a FREE language called Python. "Invent with Python" was written to be understandable by kids as young as 10 to 12 years old, although it is great for anyone of any age who has never programmed before. For more on this free book, visit Invent with Python at <a href="http://inventwithpython.com/
">http://inventwithpython.com/
</a>

AND

Scratch is a programming language that makes it easy to create your own interactive stories, animations, games, music, and art -- and share your creations on the web. As young people create and share Scratch projects, they learn important mathematical and computational ideas, while also learning to think creatively, reason systematically, and work collaboratively.For more information about Scratch see this website: http://scratch.mit.edu/?goback=.gde_1331...

Most languages have similarities that allow someone who knows one programming language to have an easier time picking up another - while these are not what you consider machine codes, it's still a start in the right direction for people who are serious about these industries.

Edited 1 times. Last edit by Kiersten Samwell on 30th March 2011 5:43pm

Posted:3 years ago

#10
As someone who's used assembly code as a student, I'm going to have to advocate the idea that teaching it to kids is a form of child abuse. =P

Posted:3 years ago

#11

Andrew Jakobs
Lead Programmer

236 96 0.4
haha, I completely agree with the author, original basic is so easy to understand... And I must admit I found coding x86 assembly (32bit that is) almost as easy as writing basic because there wasn't that many opcodes.. (I said 32bit because of having one memory space and not 16 bit with segments which was a bitch to code for IMHO)..
But the problem with a lot of coders these days is they really don't use the maximum of the computer because they are using big slow frameworks, and a lot really don't have any idea what goes on under the hood.. Missing that conception you cannot write optimal code.. but then again, most coders don't even care anymore, they just tell you to upgrade your proc or memory instead of optimizing their own code..

Posted:3 years ago

#12

David Long
a bit of this... a bit of that...

7 0 0.0
Completely agree. I went from Basic on the vic20 and c64 to Assembler and it seemed like a logical and natural step once I couldn't get the speed I needed out of Basic. I was 10 to 12 at the time. I think... maybe younger.

I'm now getting back into programming and finding it VERY hard. Mostly because I never learned C or C++ back then, so OOP is a tricky beast, and the multiple layers of abstraction are hard now. For me. I also wish for a simpler method of getting down and dirty with a modern thing like... say.... Assembler for iPhone. that would be fun.

The Unity game engine is the best way I've found to come to terms with OOP. As all the objects you see can be thought of as objects originating from classes, and scripts on objects are kind of classes. But the languages it uses aren't good for learning. With the possible exception of Boo. And there's the massive abstraction of the interface of Unity... it's kind of like Logo and the turtle thingy on steroids.

Maybe someone could write an app for iPhones that acted like Basic, allowing kids to make it do things within in a framework that gave them a feeling of direct control of the features of the device... I dunno how'd you try teach someone about programming these days, I tried recently...

A relative of my wife's, just on 18 has become very good at mathematics and loves equations, yet had no idea those talents would be best implemented in programming 3D graphics. I didn't even know where to start on how to see what programming does in the modern world of computers... Xcode and Visual Studio are abstraction multiplied. DirectX and OpenGL an abstraction ontop of an abstraction.

So where do you go to teach a kid to draw geometry on a screen in a way that helps them see how a computer does the drawing without getting too much shit in the way?

Posted:3 years ago

#13

Mark Beynon-Clarke
3D Artist

4 0 0.0
run winuae and sit them in front of AMOS. job done.

Edited 1 times. Last edit by Mark Beynon-Clarke on 30th March 2011 7:46pm

Posted:3 years ago

#14

Owen Conniss
Indie Game Dev

2 0 0.0
When I was 12 I started programming my ZX Spectrum+ in BASIC, but swiftly move on to machine code when I learned that this was why retail games were faster than my own. We could not afford an assembler so I was writing direct in hex. No one had told me it was not supposed to be possible, so it seemed normal. :)

Can't remember much of it now of course. Filled my head with too much other stuff. :(

Posted:3 years ago

#15

Ian Masters
Director

1 0 0.0
Great article Dylan.

I also think Tom has a point saying "When i was 13 i was not interested in Logo because games and demos were written in something else". On that note, if you've not seen Corona SDK yet I recommend checking it out. It's also Lua based which is a great language itself.

Corona - Physics in 5 Lines

Oops, almost forgot. Proof kids can use it:
Bubble Ball by Robert Nay 14 years old developer

Edited 1 times. Last edit by Ian Masters on 30th March 2011 10:15pm

Posted:3 years ago

#16

Peter Stirling
Software Engineer

25 7 0.3
Graphical programming is far more rewarding than low-level coding. When I was young I used Kilk 'n' Play, these days there is better software available such as 'Alice'.

Edited 1 times. Last edit by Peter Stirling on 31st March 2011 12:03am

Posted:3 years ago

#17
Ian - thanks for that link, it's been great seeing all these little frameworks come out of the woodwork in the comments section (have a read through the comments section in the original article over on altdevblogaday.com too).

Posted:3 years ago

#18

Andreas Firnigl
senior designer

9 0 0.0
What do people think about stuff like LBP2 as a teaching tool? To me it seems a really great way of showing kids how logic gates work. And it allows them to get something playable up and running in a matter of minutes. I think visual scripting/programming is getting more and more common with stuff like kismet so easy for non coders like me.

Great article by the way. I still have my brother's c64 sitting in a cupboard so I might dig that out when my daughter is a little older. Maybe she can teach me some stuff!

Posted:3 years ago

#19

João Namorado
Project Manager

52 23 0.4
I highly recommend Scratch (see Kiersten Samwell's comment). I have seen 6/7 year olds create their own games and animations with ease because of the simplicity of joining "blocks" together.

It may not be pure code but it is definitely a great first step into programming.

Posted:3 years ago

#20

Paul Shirley
Programmers

178 150 0.8
Dropping random youngsters into assembler (or even old style BASIC) is a great way to separate the natural programmers from the rest of the herd, who will just run away confused. Problem is the natural programmers would manage to do something magical whatever you started them with!

I think we forget that those of us that survived the 8bit days are those natural programmers and put up with frustrations that normal folk wouldn't accept. With no compelling performance reason assembly is not a good 1st or 2nd 'language' now. Apart from the extreme frustration simple errors bring it actually brings more complication than a language like BASIC - memory/variable allocation, the difference between registers and memory, the lack of symbolic binding for variables in registers, type conversion and the arbitrary rules all CPU's inflict on allowable op,operand combinations. At least BASIC hides all that behind a simple abstraction, you don't need to worry about where a variable exists or how you use it.

Beyond that without a minimum set of abstractions it's not easy to build an interesting program. If it's not interesting it won't keep the attention of a learner, especially a young one. Until you understand the abstraction there's not much point learning about it's implementation. Asm forces you to learn implementation while still struggling with understanding. Not good.

For learning a decent visual debugger seems seems ideal, single stepping through source powerfully illustrates program flow. There's nothing quite like seeing how things happen over describing them. Interpreted is essential, so the system doesn't fall over before telling you what went wrong.

Personally I quite like more advanced versions of BASIC, excluding Microsofts perversion of the language. Then again, I like Forth and think in assembler. Very abstracted assembler (think compiling Z80 source in a 6502 assembler ;)

Posted:3 years ago

#21

Christopher Hardwick
Software Engineer

5 0 0.0
Blitz Basic on PC... ? Or better still C# and XNA.

Wanna do some ASM? Anything with an ARM chip like an iPhone or iPod Touch, that'll pretty much cover it, only a small about of 'C' required. Or maybe some of the homebrew GBA type stuff, that's before you even contemplate emulators.

That's my take.

Posted:3 years ago

#22

David Long
a bit of this... a bit of that...

7 0 0.0
@Christopher Hardwick

Any chance you could point out how to do ASM on iPod/iPhone. I'd LOVE to try that.

Posted:3 years ago

#23

Keldon Alleyne
Handheld Developer

448 419 0.9
Great article, I agree totally with what you're saying.

I too, started learning BASIC when I was about 10/11, binary code when I was 7, assembler when I was 13, and I think I got into C a year after. By 16 I was hacking Z80 assembler on the Gameboy and counting opcode cycles and began to write tutorials based on the same philosophy you mention in your article (* no longer available on the web). My tutorials taught 12 year olds assembly coding, and they quickly got into gameboy programming.

I also got into Win32 Assembly coding, which I found remarkably easy to learn, especially since I knew exactly what was going on I had much less questions on what was happening.

Assembly code with the old processors is so easy to understand, you can conceptualize the entire instruction set with physical objects. You have a great deal less to explain, and game programming is so fun, you have direct access to the hardware that just does what you tell it to do.

I do think that high level languages can have their place, for example right brained people can focus on program design, but left brained people ought to get their teeth into assembly code.


Edit: *Removed link

Edited 2 times. Last edit by Keldon Alleyne on 19th April 2011 1:47pm

Posted:3 years ago

#24

Semi Essessi
Experienced Rendering Programmer

3 0 0.0
"BASIC doesn't exist anymore either, not as far as I'm aware anyway, so my question to the readership is, given the pre-requisite of "little to no abstraction", do you know of a good replacement for the old BASIC -> Assembler path of learning for pre-teens that produced so many amazing programmers during the 80s and very early 90s?"

QBasic 7.1 can still be found if you look around and there are lots of free assemblers... nasm, yasm etc. Although my intro to assembler (and real machine code in hex) was through VC++'s inline assembler.

Posted:3 years ago

#25
It's a wee bit like teaching a kid who wants to play rock guitar, classical or god forbid the piano instead as a grounding. I agree with the theory however one problem with teaching kids anything is keeping them engadged and I suspect they will find this totally unrelevent and boring (due to what you can do and the time it takes).

Sometimes going the other way may be more benificial, teaching them a design package then how to script and then how to write the code that is run by the scripts. I think it also depends on the kid and what they want to do eventually.

Not eveyone is going to find a job doing what John Carmack does.

Edited 2 times. Last edit by John Owens on 4th April 2011 4:41pm

Posted:3 years ago

#26

Peter Johnson
CEO

8 1 0.1
As someone who taught themselves to write machine code games back in the 80s fairly easily, I can totally see where this author is coming from, it was a heck of a lot easier then than grappling with iOS was at first for me last year after 15 years in production away from coding.

If you went straight in with the machine code route you'd need to supply some sort of easy-to-use graphical element too to make it gratifying to kids. the BBC micro had easy to use OSWRCH and OSFX function calls that let you easily change screen colours and draw simple shapes from machine code, but even that made it much easier to get started and see a result immediately.

As another poster suggested, I do think Little Big Planet provides a fantastic backgrounding in the ways of thinking that computers, and particularly games, demand, and even across many other related areas like how sequencers work, that can be tried before they start coding. It's such a creative tool that my 9 year old still spends several hours a day working on his levels over a year after the original launch. It is almost the modern-day equivalent of the Spectrum in some ways as it puts the means to create in the hands of kids, with the fairly immediate gratification they require at first. I am sure being hooked on this will translate into a desire to go further.

Peter Johnson
Www.solubleapps.com/MailShot easy group email right in your iPhone address book

Posted:3 years ago

#27

Login or register to post

Take part in the GamesIndustry community

Register now