How does a computer work?

After taking apart my keyboard to clean up the coke I had just spilled on my keyboard, I began to wonder about how the computer worked. It is fairly obvious that the keyboard simply provides an array of switches which at any given moment are on or off. The same is probably true for any device connected.
Obviouslty from here it must scan the input devices and “read” the state of all of these switches. What then? I know that the operating system has to tell the computer how to respond to the key I pressed, but how does the operating system know how to do this? How can I build my own simple computer (like the Altair)?

Extremely general questions (like yours) that are akin to “How does a car work?” would best be pursued with the purchase of a CD Encyclopedia like Encarta 2000 et al that could trace out the guts of a PC and give historical and hypertext pointers for context more effectively than this forum. You’re asking a question that would take pages and pages (and more pages!) to answer effectively.

And… forgive me for being cynical… but when I hear someone using language like this…

"It is fairly obvious that the keyboard simply provides an array of switches which at any given moment are on or off. The same is probably true for any device connected.
Obviously from here it must scan the input devices and “read” the state of all of these switches. What then? I know that the operating system has to tell the computer how to respond to the key I pressed, but how does the operating system know how to do this?
I get the impression of a very intelligent young person who is very technologically literate and with a few keystokes could call up this info on the web themselves from any number of search engines.

Why us? Summer school homework assignment?

BTW I might have an extra copy of Encarta 2000 around and if you send me your address I’ll mail it to you.

Basically, the next step following a keyboard press is for the computer to figure out where that input came from and to decode it. You’re right that this is handled by the operating system (OS). There are several ways for the OS to do this but a common method is to use an “interrupt request”. This is a hardware switch built into the CPU. When it is activated it tells the CPU to stop what it’s doing and examine what’s on the input lines. The interrupt requests are numbered (usually 0-7) and a particular request comes from a particular device. The hardware manufacturer is responsible for connecting the wiring correctly so that a keyboard request really comes from the keyboard.

The software that handles the interrupt request can then decode the keypress (“He pressed an ‘A’”) and pass it to whatever routine handles keyboard input.

There are other ways of doing this, some more sophisticated, some less so.

There is both good news and bad news in terms of building your own computer. If you mean “Can I buy the parts and put them together myself?” the answer is yes, and probably save yourself money at the same time. Buy a case, a power supply, a motherboard, a CPU, some RAM, a monitor and keyboard, mouse, disk drives, etc. It’s not hard, but it can be a little involved, especially if you’re a newbie to computer hardware. OTOH, if you mean “Can I buy some chips and a soldering gun and create my own computer, write my own OS and be the first in a new wave of computer billionaires?” The answer is still yes but there are a lot of hedges around it.

You can buy CPU chips from the manufacturer and accompanying manuals that tell you what each pin does. Assuming you have the electrical know-how to get the correct voltages and impedance matching, etc., to the pins, all you have to do is send the logically correct signals to the correct pins in the correct order with the correct timing and you can make the computer do anything you want.

The Golden Age for this kind of project has, unfortunately, passed. Back when Byte magazine carried schematics and assembly code everyone was doing just that. I designed a couple of computers myself and actually built one using a Motorola 6809 chip. But you can still do it, if you’re determined. It will provide you an excellent but informal education.

An alternative is to take a couple of entry-level computer science courses at your local community college. Find a course that talks more about hardware and assembly-language programming than applications or high-level languages.

Good luck.

Try howthingswork.com

For some fun reading, although it is out-of-date, try “Soul of a New Machine” by Tracy Kidder. It’s about the development of a minicomputer at Digital (I think). Has lots of information about what computers do inside.

pluto wrote

pluto, thanks for the flashback. It’s true; the build-your-own experience just ain’t available anymore. I still have my copy of Byte #1, and fond memories of building an 8080 machine and coding it in binary. I think JMP was C3 and RET was C9, now there’s a waste of neurons.

Christopher, no good suggestions beyond what’s already been mentioned. I’ll warn you that the computer is a bit more complicated than the keyboard, but you sound a like a sharp guy. I’m sure howthingswork.com or Encarta or another encylcopedia will give you lots of info.

You might also want to check out the How do computers work? Mailbag article.

I suggest you read Part 5, “The Digital Domain,” in the book The New Way Things Work by David Macaulay, published by Houghton Mifflin Company. Very informative and easy to understand.

Quickly! :slight_smile:

I still remember in my first year of my CIS degree, a none-too-bright girl asking this question (not that I’m comparing here). My CIS instructor calmly replied “Magic…”. The girl eventually dropped out…

And if you really want to learn, The Art of Electronics by Horowitz and Hill is an awesome textbook. There is also a Student Manual for this textbook with the schematics for building a simple computer using a Motorolla processor, including some I/O (2-digit display and a 10-key keyboard - no monitors or full keyboards of course.)