Code_ The Hidden Language of Computer Hardware and Software - Charles Petzold [101]
Opcode
Instruction
32
STA [aaaa],A
3A
LDA A,[aaaa]
In addition to the accumulator, the 8080 contains six registers that can also hold 8-bit values inside the microprocessor. These registers are very similar to the accumulator; indeed, the accumulator is considered to be a special type of register. Like the accumulator, the other six registers are latches; the processor can move bytes from memory into registers, and from registers back into memory. The other registers, however, aren't as versatile as the accumulator. When you add two 8-bit numbers, for example, the result always goes into the accumulator rather than into one of the other registers.
The six additional registers in the 8080 are named B, C, D, E, H, and L. The first question people usually ask is, "What happened to F and G?" and the second question is, "And what about I, J, and K?" The answer is that registers H and L are so called because they're special in a certain way. H stands for high and L stands for low. Very often the 8-bit quantities in H and L are treated in tandem as a 16-bit register pair named HL, H being the high-order byte and L being the low-order byte. This 16-bit value is often used to address memory. We'll see how this works shortly.
Are all these registers necessary? Why didn't we need them in the Chapter 17 computer? In theory, they aren't necessary. But they turn out to be very convenient. Many computer programs juggle several numbers at the same time. It's easiest to do this if all the numbers are stored in microprocessor registers rather than memory. The program is usually faster as well: The fewer times a program needs to access memory, generally the faster it will run.
No fewer than 63 opcodes are devoted to a single 8080 instruction called MOV, which is short for Move. This instruction is just a single byte. The instruction usually moves the contents of one register into another (or the same) register. The large number of MOV instructions is a normal consequence of designing a microprocessor with seven registers (including the accumulator).
Here are the first 32 MOV instructions. Remember that the destination is the argument on the left and the source is the argument on the right:
Opcode
Instruction
Opcode
Instruction
40
MOV B,B
50
MOV D,B
41
MOV B,C
51
MOV D,C
42
MOV B,D
52
MOV D,D
43
MOV B,E
53
MOV D,E
44
MOV B,H
54
MOV D,H
45
MOV B,L
55
MOV D,L
46
MOV B,[HL]
56
MOV D,[HL]
47
MOV B,A
57
MOV D,A
48
MOV C,B
58
MOV E,B
49
MOV C,C
59
MOV E,C
4A
MOV C,D
5A
MOV E,D
4B
MOV C,E
5B
MOV E,E
4C
MOV C,H
5C
MOV E,H
4D
MOV C,L
5D
MOV E,L
4E
MOV C,[HL]
5E
MOV E,[HL]
4F
MOV C,A
5F
MOV E,A
These are handy instructions to have. Whenever you have a value in one register, you know you can move it to another register. Notice also the four instructions that use the HL register pair, such as
MOV B,[HL]
The LDA instruction shown earlier transfers a byte from memory into the accumulator; the 16-bit address of the byte directly follows the LDA opcode. This MOV instruction transfers a byte from memory into register B. But the address of the byte to be loaded into the register is stored in the register pair HL registers. How did HL come to hold a 16-bit memory address? Well, it could happen in a variety of ways. Maybe the address was calculated in some way.
To summarize, these two instructions
LDA A,[aaaa]
MOV B,[HL]
both load a byte from memory into the microprocessor, but they use two different methods to address memory. The first method is called direct addressing and the second method is called indexed addressing.
The second batch of 32 MOV instructions shows that the memory location addressed by HL can also be a destination:
Opcode
Instruction
Opcode
Instruction
40
MOV B,B
50
MOV D,B
60
MOV H,B
70
MOV [HL],B
61
MOV H,C
71
MOV [HL],C
62
MOV H,D
72
MOV [HL],D
63
MOV H,E
73
MOV [HL],E
64
MOV H,H
74
MOV [HL],H
65
MOV H,L
75
MOV [HL],L
66
MOV H,[HL]
76