Monthly Archives: July 2011

Designing a full adder with logisim

An anonymous commenter suggested that I look at logisim, a circuit simulator written in Java. It has many nice features. For instance, you can specify a combinatorial circuit either as a truth table or as equations, and it will convert to the other representation (in minimized forms) and will also build a circuit to implement those equations. You can tell it to use only 2 input gates, or even to use only NAND gates, and it will layout a little circuit to implement it.

For instance, I entered the truth table for a full adder, and told it just to use 2 input NAND gates. The resulting (29 gates? I didn’t count carefully) 1 bit full adder emerged as a circuit:

Pretty neat. I am not sure that logisim is quite good enough to design an actual, physical CPU (it doesn’t model propagation delays, as far as I can tell) but it’s a very good tool to exercise your nascent digital design skills. Check it out.

Shouldn’t we use programming languages with fewer bad parts?

I was reading that Stanford has begun teaching their introductory computer science course CS101 with Javascript. Despite a lot of the propaganda surrounding the web and a pretty good book on the good parts of Javascript, I can help but think that Javascript has some really tragic flaws. Dijkstra famously referred to PL/1 as “the fatal disease, belonging more in the problem set than in the solution set”, and I kind of feel the same way about Javascript. Yes, it is in every browser now, so it is perhaps the most widely deployed programming language you can find, but it’s got quite a few absolutely horrific features in it. The == operator has some astoundingly obtuse behavior. Automatic semi-colon insertion is simply idiotic. Crockford documents several more features he finds questionable, most of which I think are questionable, because they mirror features in other common languages.

Crockford advises that we use tools which check our use of these questionable features, but wouldn’t it simply be better if the language didn’t contain these features in the first place? We know that some features are bad, so why are they retained in the language? Are we forever to be saddled with error prone and silly features?

Maintenance on twitter/facebook posts for my blog…

I apologize. My blog has been remarkably unsociable. Whenever I post to it, I’d like it to also post a short notice to facebook and to twitter. But recently some hiccup happened, and two posts would end up on twitter, and an annoying three would appear on facebook. I think I’ve got that sorted out. Hopefully I haven’t irked too many of you, and this will work as expected from now on.

DIY Computer Project

Continuing my obsession with reading up on homebrew CPU projects, I found this incredible blog. Instead of just presenting the completed design, Dawid has presented intermediate posts about his project in progress, detailing some of the choices and techniques he had to make along the way. As is true of most projects like this, it’s hard to know how to get started and gain enough traction to make progress, and details like this can be really helpful and really inspiring.

DIY Computer Project

Addendum: For instance, I’ve been considering writing a gate level simulator (writing code is something I feel comfortable doing) rather than spending huge amounts of time learning Verilog or VHDL. It is somewhat reassuring that Dawid apparently did the same thing. Very interesting.

Some thoughts on the last Space Shuttle launch…

This morning, I was a bit late coming into work. I decided to sit until 8:26AM Pacific to see if Atlantis would be launched on the final mission of the Space Shuttle program. Low cumulus clouds threatened, but in the end the shuttle rose on its pillar of fire for the last time, and in eight and half minutes, discarded its main fuel tank and was safely in orbit.

Reporters have been trying hard to find some perspective on the event, and in my experience, mostly failing. They put microphones in front of kids and ask them if they want to travel to space someday. They talk to astronauts and former astronauts and ask what it was like to be in space.

I think all that is slightly off the mark.

I was born in 1964, and was a child of the Apollo space program. I remember watching the first tentative steps of Neil Armstrong on the moon on our old Zenith black and white set. Even at that young age, I was interested in space and astronomy. It was a few years later that computers entered my consciousness and come to dominate my time, but I continued to be interested in space and astronomy.

For kids my age, the usual default answer to “what do you want to be when you grow up?” was “an astronaut.” But more than just being an astronaut, there was sense of optimism: that if the moon was reachable, what other achievements could we reach if we applied our energy and our industry. We dared imagine a world without hunger, and without poverty. Diseases? Cured. Poverty? Eliminated! Ignorance? Educated.

Perhaps it was just a dream, but it was a healthy one. It was a dream that challenged us to greatness.

This morning, Atlantis launched for the last time. Vying for attention on CNN was President Obama, who held a press conference to discuss the meager 18,000 jobs that were created in the last month, the weakest performance since September of last year. When coverage returned to the launch, reporters interviewed a number of people, and the question of the expense of the launch was mentioned. After the launch, the economic news reasserted itself. One reporter said that the growth industries for the next year are likely to be in retail sales and in food service.

I was lucky. As a kid, I dreamed of being an astronaut. Today? Kids dream of being to make just a little more than minimum wage. It’s a pity that I didn’t see my wish fulfilled, but it’s a tragedy that a generation of young Americans won’t experience their dream, even as limited as they are.

Here’s the reality: the space program is little more than a jobs program. Certain industries and certain states (CA, FL, MD, TX) benefit from our dreams of slipping the surly bonds of earth, but the vast majority of Americans don’t get nearly as much benefit. In purely economic terms, the Space Shuttle is a disaster: it never delivered the cost savings that optimistic forecasters suggested were possible in boosting satellites to orbit. So, people argue that the money would be better spent elsewhere, that our dreams are simply too expensive.

The U.S. military spent more on air-conditioning temporary structures in Iraq and Afghanistan than NASA spends in a year. While I appreciate and laud the efforts of our troops, I can’t help but think that cutting our dreams so we have enough money to air condition tents isn’t the kind of society that we should be dreaming about.

For a generation, the space program provided us with inspiration and optimism. As the shuttle program winds down, for all its faults it still seems like the end of a dream. I can’t help but wonder what dream will unite the next generation of Americans in their quest for greatness.

Are you a mentor, or are you just getting in the way?

It’s Friday, and Fridays are good days for thinking. It’s unclear that it is a good day to write about what you’ve been thinking, but here goes anyway.

I’m involved in a couple of different communities (hacking and amateur radio) which might be characterized as “ageing”. As a young adult, I was influenced by Steven Levy’s Hackers: Heroes of the Computer Revolution. It gave a name to the kind of computer exploration that I was interested in, and the description of the early MIT hacker community showed that there were other people in the world who were interested in understanding and programming these amazing machines. Despite the fact that I was coming onto the scene as part of the microcomputer revolution of the 1980s, I felt that the spirit of these hackers was akin to my own. They seemed to experience the same odd pleasure that I got when exploring a machine, and making it do something unusual or unexpected. Many people in this community who are my age are interested in trying to instill some of these ideals into a younger generation of hackers, and have asked what we can do to mentor them along.

In amateur radio, there is a long history of “Elmers”: hams who help younger and more inexperienced hams by giving them the benefit of their experience. There is little doubt that the ham radio community is aging: while attending Pacificon last year, I suspect I was in the youngest two percent of attendees, and I’m in my late forties. It’s a very common thing for hams to actively seek ways to bring new blood into the ranks of the licensees. For some, it’s just a way to help ensure the continued use of the frequencies that they enjoy, but I would suspect that the majority of hams merely want to pass on some of the experiences and joy that they have derived from their favorite hobby.

But here is my somewhat skeptical observation: neither community does a very good job. And frankly, that’s been a source of some puzzlement on my part. For all the effort that we expend trying to extol the virtues of computer exploration or the construction and use of radios, we aren’t attracting huge numbers to the hobby. In fact, I suspect that this kind of advocacy hasn’t resulted in any measurable increase in either community. Why is that?

I suspect it is because mentors don’t actually create interest in subjects. No amount of extolling the virtue learning about antennas or building radios or learning CW ever convinces anyone that they should become a radio amateur. No promoting of the virtues of programming, learning the internals of machines or security will ever make it interesting to someone who isn’t already curious and interested. Either you find such things interesting, or you do not. No amount of advocacy can turn your apathy into interest.

Consider it this way: I’m deeply uninterested in fashion. There are people who nonetheless view it as their passion, as a source of considerable joy in their lives. That’s actually okay. I’m just not one of them, and no amount of cajoling on their part is likely to change my mind.

I’m also relatively (and somewhat oddly) unmoved by music. For me, piano lessons was always mostly a chore. I simply don’t experience the joy and emotions that people get from listening to most music. Intellectually, I can appreciate it, but I don’t feel passionate about it.

If I can’t be mentored into a passion for music and fashion, why am I puzzled when my own efforts to mentor people into things I do enjoy fall mostly on deaf ears?

That’s not to say that mentors can’t be helpful: they absolutely can. The experience of people is incredibly useful, and can help the inexperienced see farther and better than they could stumbling on their own. And, if you happen to find a mentor who has gone along a path you are already interested in, they can serve as inspiration. But they do not themselves create the passion and drive that makes a person try to master a new subject. TThat comes from individuals themselves, and it is inappropriate for “mentors” to imagine that it is through their own virtue that their passions are perpetuated.

A couple of illustrative examples of how things can go wrong:

To become a ham radio operator, you need to become licensed, which means passing a relatively straightforward exam. The entry level license is for a “Technician” class license, which basically requires getting 70% correct on a multiple choice test drawn from a published question pool. It’s not very hard, and in fact a great many ham radio clubs hold “ham cram” events, where they meet for a day to try to cram enough stuff into your head so that you can pass the exam the same day.

One particular ham I know hates these events. His claim is that these events are “cheating” and that they deny the new licensees the opportunity to learn the material “properly”. He usually follows this with a story about how he learned this stuff. How he had to be licensed as a novice, and had to upgrade. How he had to master Morse code, work his way up through the license classes. How he learned to do everything at the foot of his mentors, and how he was glad they were around. He’ll then usually lapse into a diatribe about how kids today “play too many video games” or “don’t work hard like we used to” or “feel they are entitled”.

It makes me groan inside.

A ham radio license isn’t a diploma. It’s a license, just like a fishing license. It grants limited, uses of a shared public resource. Without it, you can’t transmit on amateur frequencies. Hence, it’s really just a road block: it gets in the way of you experiencing the thing that you might be passionate about. From my perspective, you should figure out a way to get licensed so you can get on with your passion. From my friends perspective, that road block should be as high as possible, so you really deserve the privileges you enjoy.

He’s not a bad sort, really. He thinks he’s helping novices, but in reality he’s just trying to shore up the road blocks that keep people from entering the hobby. His “mentoring” is significantly blunted by his desire to make people “pay their dues”.

I’ve heard a number of people speak on “how do we encourage the next generation of hackers”. I similarly find these kinds of talks misplaced. When I reread Levy’s Hackers, I experienced some nostalgia, but I also thought there was a lesson to be learned. Levy highlighted three different groups of hackers: the original MIT hacker community which grew up around the PDP-1, the Hardware Hackers who brought about the Altair computer, and the game hackers who surrounded Sierra Online. What I think is amazing is that none of these stories gave any hint of the revolution in computing that was to come. The rise of the Internet, search and social media simply isn’t visible in this book. Richard Stallman is mentioned as the “last real hacker”, with a sort of wistful nostalgia, with the near certainty that he will simply fade into obscurity, totally missing the revolution of free and open source software that he helped inspire. There is no sense that some of the early work of (say) the Xerox Alto would eventually fuel the second phase of Apple’s existance, and ultimately change pretty much everything about computers.

In other words, much of the “hacker” revolution that some of us (myself included) like to refer to with a sense of wistful nostalgia wasn’t as closely linked to the revolutions that were to come as we would like to imagine. When we draw on our own early experiences to try to find ways to educate or inspire newcomers, we often do so through this overly narrow view of history. We might think that “really” understanding machine code or architectures are important, and that the only way to do that is to go through the same sort of exercises that we did. But consider this: if we would have had access to the machines and information back then, we wouldn’t have tolerated this kind of spoon feeding either. We would have simply grabbed all that we could in pursuit of our passions.

Young people today are no different.

Here’s my recipe for success: don’t bother trying to recruit people to your passions. The best you can do is find those already interested, and make it easy for them to find you. Use social media. Publish your passions on your blog. Do what you love, and do it visibly. And when you find others who enjoy the same thing, try to engage. Do stuff. Collaborate. Gather. Exchange.

And most importantly: don’t try to convince someone that the way you enjoy something is the only proper way. Don’t dismiss their approach to their passions, simply because they aren’t the same as your own. Seek to help remove the roadblocks that keep them from progressing, don’t introduce new ones yourself to justify your own approach.

And most of all, have fun, and keep doing what you are doing!

What do you all think?

A basic simulator for Caxton Foster’s “Blue” Architecture…

Yep, been spending some time thinking about homebrew computer architectures. I’ve also been reading Gordon Bell’s Computer Engineering, pondering some of the older and earlier computing architectures. Caxton Foster’s Computer Architecture describes a simple computer architecture called “Blue”, which has only 16 instructions, and uses only direct addressing. It’s a pretty primitive machine (more like a PDP-8’s out of work cousin), but in 30 pages, Foster describes pretty much the complete circuitry needed to implement the machine. I thought I’d write a simple behavoral simulator just to play with, and to see how much of a pain it is to program (answer: pretty big). For now, here’s the code. More later.

#include <stdio.h>
#include <stdlib.h>

/*  _    _          
 * | |__| |___  ___ 
 * | '_ \ / _ \/ _ \
 * |_.__/_\___/\___/
 *                  
 * An implementation of the simplest version of Caxton Foster's "Blue" 
 * machine as described in his book _Computer Architecture_, Third
 * Edition, Copyright 1985.   Just meant to stimulate some experimentation.
 * 
 * The architecture described is _very_ simple, consisting of just sixteen
 * instructions, a single accumulator, no CPU flags like carry or overflow,
 * and only direct addressing.  This makes programming pretty annoying, 
 * virtually requiring self-modifying code to do anything non-trivial.
 * But in 30 pages, Foster presents pretty much the entire architecture, 
 * which made me spend 15 minutes to code up a simple behavioral simulator 
 * and play around with it.
 */

typedef unsigned short Word ;

#define MEMSIZE         4096

Word M[MEMSIZE] = {
        0x600C,
        0x100B,
        0x9004,
        0x0000,
        0x700C,
        0x6008,
        0x100B,
        0x7008,
        0x600C,
        0xC000,
        0xA000,
        1,
        -13,
        'H',
        'e',
        'l',
        'l',
        'o',
        ' ',
        'W',
        'o',
        'r',
        'l',
        'd',
        '!',
        '\n'
} ;

Word A ;
Word Z ;
Word MAR ;
Word MBR ;
Word PC ;
Word IR ;
Word CS ;

void
fetch()
{
    Word t ;

    /* fprintf(stderr, "... 0x%04x ", PC) ; */
    IR = M[PC] ;
    PC ++ ;
    PC &= (MEMSIZE-1) ;
}

void
execute()
{
    int op = IR >> 12 ;
    int addr = IR & 0xfff ;

    /* fprintf(stderr, "%0x %03x\n", op, addr) ; */

    switch (op) {
    case 0:             /* HLT */
        fprintf(stderr, "\n... bloo executed HLT.\n") ;
        exit(0) ;
    case 1:             /* ADD */
        A += M[addr] ;
        break ;
    case 2:             /* XOR */
        A ^= M[addr] ;
        break ;
    case 3:             /* AND */
        A &= M[addr] ;
        break ;
    case 4:             /* OR */
        A |= M[addr] ;
        break ;
    case 5:             /* NOT */
        A ^= 0xFFFF ;
        break ;
    case 6:             /* LDA */
        A = M[addr] ;
        break ;
    case 7:             /* STA */
        M[addr] = A ;
        break ;
    case 8:             /* SRJ */
        A = PC & 0xFFF ;
        PC = addr ;
        break ;
    case 9:             /* JMA */
        if (A&0x8000)
            PC = addr ;
        break ;
    case 0xA:           /* JMP */
        PC = addr ;
        break ;
    case 0xB:           /* INP */
        A = getchar() ;
        break ;
    case 0xC:           /* OUT */
        putchar(A) ;
        fflush(stdout) ;
        break ;
    case 0xD:           /* RAL */
        if (A & 0x8000)
            A = (A << 1) | 1 ;
        else
            A = (A << 1) ;
        break ;
    case 0xE:           /* CSA */
        A = CS ;
        break ;
    case 0xF:           /* NOP */
        break ;
    }
}

int
main(int argc, char *argv[])
{
    for (;;) {
        fetch() ;
        execute() ;
    }    
    return 0 ;
}

John Doran’s D16 Homebrew Computer

Just another link to inspire me in my glacial moves toward designing a CPU of my own:

The D16/M is a general-purpose, stored-program, single-address, 16-bit digital computer using two’s complement arithmetic. It manages subroutine calls and interrupts using a memory stack. The processor may directly address 64K words of memory or I/O. Its timing and control unit is microprogrammed (fully horizontal, with a 72-bit control word).

John Doran’s D16

Time for some blog maintenance…

WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.