specify the second source register, and 8–9
specify the destination register. The last six bits are not needed by register-to-register arithmetic instructions, so they’re padded with 0s (they’re zeroed out in computer jargon) and ignored.
Now, let’s use the binary values in Tables 2-1 and 2-2 to translate the add
instruction in line 3 of Program 1-1 into a 2-byte (or 16-bit) machine language
instruction:
Assembly Language Instruction
Machine Language Instruction
add A, B, C
00000001 10000000
The Mechanics of Program Execution
21
Here are a few more examples of arithmetic instructions, just so you can
get the hang of it:
Assembly Language Instruction
Machine Language Instruction
add C, D, A
00001011 00000000
add D, B, C
00001101 10000000
sub A, D, C
00010011 10000000
Increasing the number of binary digits in the opcode and register
fields increases the total number of instructions the machine can use and the
number of registers it can have. For example, if you know something about
binary notation, then you probably know that a 3-bit opcode allows the pro-
cessor to map up to 23 mnemonics, which means that it can have up to 23, or
8, instructions in its instruction set ; increasing the opcode size to 8 bits would allow the processor’s instruction set to contain up to 28, or 256, instructions.
Similarly, increasing the number of bits in the register field increases the
possible number of registers that the machine can have.
Arithmetic instructions containing an immediate value use an immediate-
type instruction format, which is slightly different from the register-type format we just saw. In an immediate-type instruction, the first byte contains the
opcode, the source register, and the destination register, while the second
byte contains the immediate value, as shown in Figure 2-2.
0
1
2
3
4
5
6
7
mode
opcode
source
destination
Byte 1
8
9
10
11
12
13
14
15
8-bit immediate value
Byte 2
Figure 2-2: Machine language format for an immediate-type instruction
Here are a few immediate-type arithmetic instructions translated from
assembly language to machine language:
Assembly Language Instruction
Machine Language Instruction
add C, 8, A
10001000 00001000
add 5, A, C
10000010 00000101
sub 25, D, C
10011110 00011001
22
Chapter 2
Binary Encoding of Memory Access Instructions
Memory-access instructions use both register- and immediate-type instruction
formats exactly like those shown for arithmetic instructions. The only
difference lies in how they use them. Let’s take the case of a load first.
The load Instruction
We’ve previously seen two types of load, the first of which was the immediate
type. An immediate-type load (see Figure 2-3) uses the immediate-type
instruction format, but because the load’s source is an immediate value (a
memory address) and not a register, the source field is unneeded and must
be zeroed out. (The source field is not ignored, though, and in a moment
we’ll see what happens if it isn’t zeroed out.)
0
1
2
3
4
5
6
7
mode
opcode
00
destination
Byte 1
8
9
10
11
12
13
14
15
8-bit immediate source address
Byte 2
Figure 2-3: Machine language format for an immediate-type load
Now let’s translate the immediate-type load in line 1 of Program 1-1 (12 is
1100 in binary notation):
Assembly Language Instruction
Machine Language Instruction
load #12, A
10100000 00001100
The 2-byte machine language instruction on the right is a binary repre-
sentation of the assembly language instruction on the left. The first byte
corresponds to an immediate-type load instruction that takes register A as its
destination. The second byte is the binary representation of the number 12,
which is the source address in memory that the data is to be loaded from.
The second type of load we’ve seen is the register type. A register-type
load uses the register-type instruction format, but with the source2 field
zeroed
Linda Howard
Tanya Michaels
Minnette Meador
Terry Brooks
Leah Clifford
R. T. Raichev
Jane Kurtz
JEAN AVERY BROWN
Delphine Dryden
Nina Pierce