Saturday, May 31, 2014

Elements of Computing Systems: Chapter 4

This has not been a great week for me. This post was SUPPOSED to be a tutorial for making fluorescent lightbulbs run on batteries. The problem being, of course, that two months and entirely too much solder into the project, my lightbulb remains unlit. Sigh. So, instead I turned to finish Chapter Four, which describes the Hack machine language you'll be using in your computer. It only has two projects at its end, so I figure I can read through it quickly and finish before I start studying for finals.

This was before I realized that in Chapter Four, ECS throws all of its rational explanations and helpful examples out the window in exchange for a list of machine language commands whose functions remain a mystery after reading the chapter three times. I didn't actually finish this project on my own. I found solutions others had programmed and studied them in order to figure out what the code actually did. And this was after studying the Hack tutorial on the Nand2Tetris website and the forums. I'll do my best to explain my problems with the chapter, but considering I'm still not sure I understand it, the explanation may not be accurate.

The first issue I encountered was in their initial explanation of machine language. Their explanation uses syntax from some language other than Hack, which was very confusing.
Then they go on to their explanation of the machine's two memory registers: A, which holds information that can be used in a command as either an address or a value, and D, which only holds values. These registers are manipulated through an @ command. The @ command is not well explained at all. The book seems to say that it works like a pointer in the A register. Actually, it loads a value into the A register. Consider this code.

@R1             // This loads the word "R1" into some space in the A register
D = M           // M refers to whatever is currently loaded in the A register, in this case R1
                      // D is the D register, which is unaffected by @ commands, so it can store values that are
                      // used by multiple @ commands.
@x                // This loads the word "x" into some space in the A register
M = D           // In a higher level language, this would translate to x = R1.
                      // The program will now read R1 everywhere you type x

Some 'memory words' (a term not defined in the book, meaning "R1" or "SCREEN" if those point to a specific memory address.) appear to be predefined addresses, but these are never listed. One of the projects involves creating multiple loops, but the syntax for loop creation is never given. At one point the chapter detours to describe how C commands translate into binary, which is both useless for the project and intensely confusing. You have to clear each memory register before you use it, but are never told to do so. The list goes on and on.

I don't understand how others were able to create their projects from this chapter. I may have done an exceptionally terrible job with the reading and missed everything I needed to know. I've never used machine language before. I had no context for how it should work. After hours of study, I was able to recreate others' solutions for the projects, and I understand the language enough now to use it. But did it really have to be that difficult?

I'm also a bit concerned that there was no chapter where we created the Assembler and CPU (unless those are created in chapter 5 and we just skipped around a bit.) I understand that they may be too complicated for the course to include, I was just expecting to build the ENTIRE computer, not just the parts of it that were convenient.

Hopefully I'll find Chapter 5 easier to understand. It probably didn't help that it was the week before finals too, and every teacher assigned every project at once. The upside is, expect project posts soon! I've got two on mindstorms and one on tech theatre costumes as soon as they get back from the school.

Then it's on to summer! And summer means robots and space camp, so you know what? Chapter Four? Still worth it for getting me that much closer to having my computer BUILT.

See you next time!


No comments:

Post a Comment