Why a Computer is like a Restaurant

To explain the inner workings of a computer, I'll make a detailed analogy with the workings of a restaurant.  The basic idea is that a computer uses an application to process data into a form that is desired by the user; a restaurant processes ingredients into a dish that is desired by the patron.  The elements of the analogy:
Computer
Restaurant
CPU
Chef & Cooking Implements
Application
Recipes
Data
Ingredients
Results
Meal
RAM
Pantry & Shelves
Disk
Offsite Stores & Suppliers
Display
Keyboard
Mouse
Menu, Waitstaff


Central Processor Model



The mental model of the computer that programmers used back in the bad old days is shown above.  A central processing unit (CPU) directly controls random-access memory (RAM), disk access, user interaction, etc.  This model is like a short-staffed "mom & pop" restaurant.  The chef not only cooks, but takes the orders, runs to the store, stocks the pantry, serves the food, etc. (Note that recipes and ingredients in the pantry (RAM) are in smaller quantities than those in the grocery store (Disk), but are more rapidly available.)  In those days the CPU was expensive, so having it do all those mundane tasks was uneconomic.  This led to the Bus Model:


Central Memory (Bus) Model




In this model, the expensive chef is confined to the kitchen; if she wants an ingredient or a recipe, she informs a manger (memory controller) who orders an underling (peripheral) to get the desired item.  In the meantime, the chef works on other tasks.  When the item becomes available, the manager puts it at a previously agreed-upon space on the kitchen shelf and interrupts the chef to let her know that the item is there.  The chef can either use it immediately, or wait 'til later.

Similarly, the chef puts a finished dish on the shelf and informs the manager; she then continues with the next task. As you can see, this makes much more efficient use of the chef, and prevents the whole restaurant from coming to a halt when an ingredient is slow in arriving.

G5 Central Memory Bus Model



The diagram of the G5 PowerMac above shows the physical implementation of the Bus Model.  An application running on the CPU thinks that it's only attached to RAM -- it can't "see" the disk, display, etc. directly.

The Boot ROM got its name in the old days; if a computer crashed, it would forget how to do anything. To teach it the minimum necessary to relearn, the operator would have to enter a small program into memory manually; there was a cheat-sheet that had a list of switches (each with its own little red light -- remember those?) that had to be put in a sequence of configurations.  Each configuration corresponded to an instruction to the CPU on how to read a paper tape that held the operating system. The program was called a bootstrap loader, because the computer was essentially lifting itself by its own bootstraps.

Nowadays the boostrap loader is stored in a piece of Read Only Memory (ROM), that cannot be corrupted by a crash. (and anyway, there aren't any switches on the front panel anymore)

6502 Chip - Apple IIe, Vic20, Commodore 64, Atari 400, 800



When we start looking at CPU chips, we need to realize that the chips don't work at the recipe level.  A compiler reads the recipes and breaks them down to more basic level.  A recipe says "Saute garlic and onions..."; the compiler would break that down to:
In our analogy, the 6502 chip used in the Apple IIe would be like cooking inside a backpacker's tent.  The cook has only one pot (Accumulator), which is big enough only to contain 8 bits.  There are also two dishes (registers) to hold intermediate (8 bit) results. A small number of instructions/ingredients (256 items) can be stored in easily-accessible Stack Data. The rest of ~4000 items take longer to get.

G5 Chip





The G5 chip is more like a busy Ivar's.  The G5 kitchen has special shelves (L1,L2 Cache) that hold often-used ingredients and recipes.  Fetch and Decode elements looks at the written instructions and hands them over to Dispatch who decides which chef gets the task.  The Execution Core units handle specialized tasks; the Velocity Engine is like an automated belt-drive broiler that can cook a lot of items simultaneously, but requires lots of throughput to be efficient.

The G5 is known as a RISC chip (Reduced Instruction Set Computer), in contrast to Intel's CISC (Complex Instruction Set) architecture.  (Should peel, slice, and add to pan be one instruction or three?) A CISC kitchen is like a McDonald's; if you want something standard, it will come out quick, but, if tastes change, it can be very inefficient in dealing with novel situations.  A RISC kitchen has very standard pots, stoves, etc. and gains its efficiency from the optimization that the recipe interpreter (compiler) imposes. A RISC kitchen will just reconfigure its way of working to deal with novel situations.

Bits, Bytes, Nybbles, and Words



Hexadecimals


Hex
Digit
Places
8421
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
A
1010
B
1011
C
1100
D
1101
E
1110
F
1111



Number Uses

    •     Logical - each bit means true/false about some situation.
    ◦     Status Register
    ◦     Bit-mapped Graphics

    •     Pointer
    ◦     Operation
    ◦     Address
    ◦     Offset
    •     Integer
    ◦     Unsigned
    ◦     Signed (2 kinds)
    •     Floating Point