Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [81]
Keep in mind that the Store instruction doesn't affect the Zero flag. The Zero flag is affected only by the Add, Subtract, Add with Carry, or Subtract with Borrow instruction, so it will remain the same value that was set the last time one of these instructions occurred.
The second time through, the 16-bit location at 1004h and 1005h will contain the value A7h times 2. The value 1Bh is added to FFh to get the result 1Ah. That's not 0, so back to the top.
On the twenty-eighth time through, the 16-bit location at 1004h and 1005h will contain the value A7h times 1Ch. At location 1003h will be the value 1. This will be added to FFh and the result will be zero. The Zero flag will be set! So the Jump If Not Zero instruction will not jump back to 0000h. Instead, the next instruction is a Halt. We're done.
I now assert that at long last we've assembled a piece of hardware that we can honestly call a computer. To be sure, it's a primitive computer, but it's a computer nonetheless. What makes the difference is the conditional jump. Controlled repetition or looping is what separates computers from calculators. I've just demonstrated how a conditional jump instruction allows this machine to multiply two numbers. In a similar way, it can also divide two numbers. Moreover, it's not limited to 8-bit values. It can add, subtract, multiply, and divide 16-bit, 24-bit, 32-bit, or even larger numbers. And if it can do this, it can calculate square roots, logarithms, and trigonometric functions.
Now that we've assembled a computer, we can start using words that sound like we're talking about computers.
The particular computer that we've assembled is classified as a digital computer because it works with discrete numbers. At one time, there were also analog computers that are now largely extinct. (Digital data is discrete data—data that has certain specific distinct values. Analog information is continuous and varies throughout an entire range.)
A digital computer has four main parts: a processor, memory, at least one input device, and least one output device. In our machine, the memory is the 64-KB RAM array. The input and output devices are the rows of switches and lightbulbs on the RAM array control panel. These switches and lightbulbs let us (the human beings in this show) put numbers into memory and examine the results.
The processor is everything else. A processor is also called a central processing unit, or CPU. More casually, the processor is sometimes called the brain of the computer, but I'd like to avoid using such terminology, mainly because what we designed in this chapter hardly seems anything like a brain to me. (The word microprocessor is very common these days. A microprocessor is just a processor that—through use of technology I'll describe in Chapter 18—is very small. What we've built out of relays in this chapter could hardly be defined as a micro anything!)
The processor that we've built is an 8-bit processor. The accumulator is 8 bits wide and most of the data paths are 8 bits wide. The only 16-bit data path is the address to the RAM array. If we used 8 bits for that, we'd be limited to 256 bytes of memory rather than 65,536 bytes, and that would be quite restrictive.
A processor has several components. I've already identified the accumulator, which is simply a latch that holds a number inside the processor. In our computer, the 8-bit inverter and the 8-Bit Adder together can be