Download presentation
Presentation is loading. Please wait.
Published byΤελαμών Γιάνναρης Modified over 6 years ago
1
The all-important ALU The main job of a central processing unit is to “process,” or to perform computations....remember the ALU from way back when? We’ll use the following general block symbol for the ALU. A and B are two n-bit numeric inputs. FS is an m-bit function select code, which picks one of 2m functions. The n-bit result is called F. Several status bits provide more information about the output F: V = 1 in case of signed overflow. C is the carry out. N = 1 if the result is negative. Z = 1 if the result is 0. A B ALU F Z N C V FS n m 11/24/2018 Datapaths
2
My first datapath Here is the most basic datapath.
The ALU’s two data inputs come from the register file. The ALU computes a result, which is saved back to the registers. WR, DA, AA, BA and FS are control signals. Their values determine the exact actions taken by the datapath— which registers are used and for what operation. Remember that many of the signals here are actually multi-bit values. D data Write D address A address B address A data B data Register File WR DA AA BA A B ALU F Z N C V FS 2 2 2 n n 5 n 11/24/2018 Datapaths
3
ALU functions For concrete examples, we’ll use the ALU as it’s presented in the textbook. The table of operations on the right is taken from page 373. We use an alternative notation for AND and OR to avoid confusion with arithmetic operations. The function select code FS is 5 bits long, but there are only 15 different functions here. 11/24/2018 Datapaths
4
An example computation
Let’s look at the proper control signals for the operation below: R0 R1 + R3 Set AA = 01 and BA = 11. This causes the contents of R1 to appear at A data, and the contents of R3 to appear at B data. Set the ALU’s function select input FS = (A + B). Set DA = 00 and WR = 1. On the next positive clock edge, the ALU result (R1 + R3) will be stored in R0. D data WR Write 1 DA D address 00 Register File AA A address B address BA 01 11 A data B data A B FS FS 00010 ALU V C N Z F 11/24/2018 Datapaths
5
Two questions Four registers isn’t a lot. What if we need more storage? Who exactly decides which registers are read and written and which ALU function is executed? D data Write D address A address B address A data B data Register File WR DA AA BA A B ALU F Z N C V FS 11/24/2018 Datapaths
6
More Storage: We can access RAM also
Here’s a way to connect RAM into our existing datapath. To write to RAM, we must give an address and a data value. These will come from the registers. We connect A data to the memory’s ADRS input, and B data to the memory’s DATA input. Set MW = 1 to write to the RAM. (It’s called MW to distinguish it from the WR write signal on the register file.) n D data WR Write DA D address Register File AA A address B address BA A data B data RAM ADRS DATA CS WR OUT MW +5V n n A B FS FS 1 V ALU C N Z F n Q D1 D0 S n MD 11/24/2018 Datapaths
7
Reading from RAM To read from RAM, A data must supply the address.
Set MW = 0 for reading. The incoming data will be sent to the register file for storage. This means that the register file’s D data input could come from either the ALU output or the RAM. A mux MD selects the source for the register file. When MD = 0, the ALU output can be stored in the register file. When MD = 1, the RAM output is sent to the register file instead. n D data WR Write DA D address Register File AA A address B address BA A data B data RAM n ADRS n DATA OUT +5V CS A B MW WR FS FS V ALU C N Z F n Q D1 D0 S n MD 11/24/2018 Datapaths
8
Notes about this setup We now have a way to copy data between our register file and the RAM. Notice that there’s no way for the ALU to directly access the memory—RAM contents must go through the register file first. Here the size of the memory is limited by the size of the registers; with n-bit registers, we can only use a 2n x n RAM. For simplicity we’ll assume the RAM is at least as fast as the CPU clock. (This is definitely not the case in real processors these days.) D data Write D address A address B address A data B data Register File WR DA AA BA A B ALU F Z N C V FS n Q D1 D0 S RAM ADRS DATA CS OUT MW +5V MD 11/24/2018 Datapaths
9
Memory transfer notation
In our transfer language, the contents at random access memory address X are denoted M[X]. For example: The first word in RAM is M[0]. If register R1 contains an address, then M[R1] are the contents of that address. The M[ ] notation is like a pointer dereference operation in C or C++. 11/24/2018 Datapaths
10
Example sequence of operations
Here is a simple series of register transfer instructions: R3 M[R0] R3 R3 + 1 M[R0] R3 This just increments the contents at address R0 in RAM. Again, our ALU only operates on registers, so the RAM contents must first be loaded into a register, and then saved back to RAM. R0 is the first register in our register file. We’ll assume it contains a valid memory address. How would these instructions execute in our datapath? 11/24/2018 Datapaths
11
R3 M[R0] AA should be set to 00, to read register R0.
The value in R0 will be sent to the RAM address input, so M[R0] appears as the RAM output OUT. MD must be 1, so the RAM output goes to the register file. To store something into R3, we’ll need to set DA = 11 and WR = 1. MW should be 0, so nothing is accidentally changed in RAM. Here, we did not use the ALU (FS) or the second register file output (BA). n 1 D data WR Write DA D address 11 Register File AA A address B address BA 00 A data B data RAM n ADRS n DATA OUT +5V CS A B MW WR FS FS V ALU C N Z F n Q D1 D0 S n MD 1 11/24/2018 Datapaths
12
R3 R3 + 1 AA = 11, so R3 is read from the register file and sent to the ALU’s A input. FS needs to be for the operation A + 1. Then, R3 + 1 appears as the ALU output F. If MD is set to 0, this output will go back to the register file. To write to R3, we need to make DA = 11 and WR = 1. Again, MW should be 0 so the RAM isn’t inadvertently changed. We didn’t use BA. n 1 D data WR Write DA D address 11 Register File AA A address B address BA 11 A data B data RAM n ADRS n DATA OUT +5V CS 00001 A B MW WR FS FS V ALU C N Z F n D0 n Q D1 S MD 11/24/2018 Datapaths
13
M[R0] R3 Finally, we want to store the contents of R3 into RAM address R0. Remember the RAM address comes from “A data,” and the contents come from “B data.” So we have to set AA = 00 and BA = 11. This sends R0 to ADRS, and R3 to DATA. MW must be 1 to write to memory. No register updates are needed, so WR should be 0, and MD and DA are unused. We also didn’t use the ALU, so FS was ignored. n D data WR Write DA D address Register File AA A address B address BA 00 11 A data B data RAM n ADRS n DATA OUT +5V CS A B MW WR FS FS 1 V ALU C N Z F n Q D1 D0 S n MD 11/24/2018 Datapaths
14
Constant in One last refinement is the addition of a Constant input.
The modified datapath is shown on the right, with one extra control signal MB. We’ll see how this is used later. Intuitively, it provides an easy way to initialize a register or memory location with some arbitrary number. D data Write D address A address B address A data B data Register File WR DA AA BA Constant MB S D1 D0 Q RAM ADRS DATA CS WR OUT MW +5V A B ALU F Z N C V FS Q D1 D0 S MD 11/24/2018 Datapaths
15
Control units From these examples, you can see that different actions are performed when we provide different inputs for the datapath control signals. The second question we had was “Who exactly decides which registers are read and written and which ALU function is executed?” In real computers, the datapath actions are determined by the program that’s loaded and running. A control unit is responsible for generating the correct control signals for a datapath, based on the program code. We’ll talk about programs and control units next week. 11/24/2018 Datapaths
16
Summary The datapath is the part of a processor where computation is done. The basic components are an ALU, a register file and some RAM. The ALU does all of the computations, while the register file and RAM provide storage for the ALU’s operands and results. Various control signals in the datapath govern its behavior. Next, we’ll see how programmers can give commands to the processor, and how those commands are translated in control signals for the datapath. 11/24/2018 Datapaths
17
Instruction set architectures
Last week we built a simple, but complete, datapath. The datapath is ultimately controlled by a programmer, so today we’ll look at several aspects of programming in more detail. How programs are executed on processors An introduction to instruction set architectures Example instructions and programs Tomorrow we’ll see how programs are encoded in a processor. Then, on Wednesday, we’ll finish our processor by designing a control unit, which converts our programs into signals for the datapath. July 22, 2002 © Howard Huang
18
Programming and CPUs Programs written in a high-level language like C++ must be compiled to produce an executable program. The result is a CPU-specific machine language program. This can be loaded into memory and executed by the processor. CS231 focuses on stuff below the dotted blue line, but machine language serves as the interface between hardware and software. Datapath High-level program Executable file Control words Compiler Control Unit Hardware Software 11/24/2018 Datapaths
19
High-level languages High-level languages provide many useful programming constructs. For, while, and do loops If-then-else statements Functions and procedures for code abstraction Variables and arrays for storage Many languages provide safety features as well. Static and dynamic typechecking Garbage collection High-level languages are also relatively portable.Theoretically, you can write one program and compile it on many different processors. It may be hard to understand what’s so “high-level” here, until you compare these languages with... 11/24/2018 Datapaths
20
Low-level languages Each CPU has its own low-level instruction set, or machine language, which closely reflects the CPU’s design. Unfortunately, this means instruction sets are not easy for humans to work with! Control flow is limited to “jump” and “branch” instructions, which you must use to make your own loops and conditionals. Support for functions and procedures may be limited. Memory addresses must be explicitly specified. You can’t just declare new variables and use them! Very little error checking is provided. It’s difficult to convert machine language programs to different processors. Later we’ll look at some rough translations from C to machine language. 11/24/2018 Datapaths
21
Compiling Processors can’t execute programs written in high-level languages directly, so a special program called a compiler is needed to translate high-level programs into low-level machine code. In the “good” old days, people often wrote machine language programs by hand to make their programs faster, smaller, or both. Now, compilers almost always do a better job than people. Programs are becoming more complex, and it’s hard for humans to write and maintain large, efficient machine language code. CPUs are becoming more complex. It’s difficult to write code that takes full advantage of a processor’s features. Some languages, like Perl or Lisp, are usually interpreted instead of compiled. Programs are translated into an intermediate format. This is a “middle ground” between efficiency and portability. 11/24/2018 Datapaths
22
Assembly and machine languages
Machine language instructions are sequences of bits in a specific order. To make things simpler, people typically use assembly language. We assign “mnemonic” names to operations and operands. There is (almost) a one-to-one correspondence between these mnemonics and machine instructions, so it is very easy to convert assembly programs to machine language. We’ll use assembly code this today to introduce the basic ideas, and switch to machine language tomorrow. 11/24/2018 Datapaths
23
Data manipulation instructions
Data manipulation instructions correspond to ALU operations. For example, here is a possible addition instruction, and its equivalent using our register transfer notation: This is similar to a high-level programming statement like R0 = R1 + R2 Here, all of the operands are registers. ADD R0, R1, R2 operation destination sources operands R0 R1 + R2 Register transfer instruction: 11/24/2018 Datapaths
24
More data manipulation instructions
Here are some other kinds of data manipulation instructions. NOT R0, R1 R0 R1’ ADD R3, R3, #1 R3 R3 + 1 SUB R1, R2, #5 R1 R2 - 5 Some instructions, like the NOT, have only one operand. In addition to register operands, constant operands like 1 and 5 are also possible. Constants are denoted with a hash mark in front. 11/24/2018 Datapaths
25
Relation to the datapath
These instructions reflect the design of our datapath from last week. There are at most two source operands in each instruction, since our ALU has just two inputs. The two sources can be two registers, or one register and one constant. More complex operations like R0 R1 + R2 - 3 must be broken down into several lower-level instructions. Instructions have just one destination operand, which must be a register. D data Write D address A address B address A data B data Register File WR DA AA BA A B ALU F Z N C V FS S D1 D0 Q Constant MB 11/24/2018 Datapaths
26
What about RAM? Recall that our ALU has direct access only to the register file. RAM contents must be copied to the registers before they can be used as ALU operands. Similarly, ALU results must go through the registers before they can be stored into memory. We rely on data movement instructions to transfer data between the RAM and the register file. D data Write D address A address B address A data B data Register File WR DA AA BA Q D1 D0 S RAM ADRS DATA CS OUT MW +5V A B ALU F Z N C V FS MD S D1 D0 Q Constant MB 11/24/2018 Datapaths
27
Loading a register from RAM
A load instruction copies data from a RAM address to one of the registers. LD R1,(R3) R1 M[R3] Remember in our datapath, the RAM address must come from one of the registers—in the example above, R3. The parentheses help show which register operand holds the memory address. D data WR Write DA D address Register File AA A address B address BA A data B data Constant MB S D1 D0 Q RAM ADRS DATA OUT +5V CS A B ALU F Z N C V FS MW WR Q D1 D0 S MD 11/24/2018 Datapaths
28
Storing a register to RAM
A store instruction copies data from a register to an address in RAM. ST (R3),R1 M[R3] R1 One register specifies the RAM address to write to—in the example above, R3. The other operand specifies the actual data to be stored into RAM—R1 above. D data Write D address A address B address A data B data Register File WR DA AA BA Constant MB S D1 D0 Q RAM ADRS DATA CS WR OUT MW +5V A B ALU F Z N C V FS Q D1 D0 S MD 11/24/2018 Datapaths
29
Loading a register with a constant
With our datapath, it’s also possible to load a constant into the register file: LD R1, #0 R1 0 Our example ALU has a “transfer B” operation (FS=10000) which lets us pass a constant up to the register file. This gives us an easy way to initialize registers. D data WR Write DA D address Register File AA A address B address BA A data B data Constant MB S D1 D0 Q RAM ADRS DATA OUT +5V CS A B ALU F Z N C V FS MW WR Q D1 D0 S MD 11/24/2018 Datapaths
30
Storing a constant to RAM
And you can store a constant value directly to RAM too: ST (R3), #0 M[R3] 0 This provides an easy way to initialize memory contents. D data Write D address A address B address A data B data Register File WR DA AA BA Constant MB S D1 D0 Q RAM ADRS DATA CS WR OUT MW +5V A B ALU F Z N C V FS Q D1 D0 S MD 11/24/2018 Datapaths
31
The # and ( ) are important!
We’ve seen several statements containing the # or ( ) symbols. These are ways of specifying different addressing modes. The addressing mode we use determines which data are actually used as operands: The design of our datapath determines which addressing modes we can use. The second example above wouldn’t work in our datapath. Why not? We’ll talk about addressing modes in more detail next week. LD R0, #1000 // R0 1000 LD R0, // R0 M[1000] LD R3, R0 // R3 R0 LD R3, (R0) // R3 M[R0] 11/24/2018 Datapaths
32
A small example Here’s an example register-transfer operation.
M[1000] M[1000] + 1 This is the assembly-language equivalent: An awful lot of assembly instructions are needed! For instance, we have to load the memory address 1000 into a register first, and then use that register to access the RAM. This is due to our relatively simple datapath design, which only allows register and constant operands to the ALU. Later on, mostly in CS232, you’ll see why this can be a good thing. LD R0, #1000 // R0 1000 LD R3, (R0) // R3 M[1000] ADD R3, R3, #1 // R3 R3 + 1 ST (R0), R3 // M[1000] R3 11/24/2018 Datapaths
33
Control flow instructions
Programs consist of a lot of sequential instructions, which are meant to be executed one after another. Thus, programs are stored in memory so that: Each program instruction occupies one address. Instructions are stored one after another. A program counter (PC) keeps track of the current instruction address. Ordinarily, the PC just increments after executing each instruction. But sometimes we need to change this normal sequential behavior, with special control flow instructions. 768: LD R0, #1000 // R0 1000 769: LD R3, (R0) // R3 M[1000] 770: ADD R3, R3, #1 // R3 R3 + 1 771: ST (R0), R3 // M[1000] R3 11/24/2018 Datapaths
34
Jumps A jump instruction always changes the value of the PC.
The operand specifies exactly how to change the PC. For simplicity, we often use labels to denote actual addresses. For example, a program can skip certain instructions. You can also use jumps to repeat instructions. LD R1, #10 LD R2, #3 JMP L K LD R1, #20 // These two instructions LD R2, #4 // would be skipped L ADD R3, R3, R2 ST (R1), R3 LD R1, #0 F ADD R1, R1, #1 JMP F // An infinite loop! 11/24/2018 Datapaths
35
Branches A branch instruction may change the PC, depending on whether a given condition is true. LD R1, #10 LD R2, #3 BZ R4, L // Jump to L if R4 == 0 K LD R1, #20 // These instructions may be LD R2, #4 // skipped, depending on R4 L ADD R3, R3, R2 ST (R1), R3 11/24/2018 Datapaths
36
Types of branches Branch conditions are often based on the ALU result.
This is what the ALU status bits V, C, N and Z are used for. With them we can implement various branch instructions like the ones below. Other branch conditions (e.g., branch if greater, equal or less) can be derived from these, along with the right ALU operation. 11/24/2018 Datapaths
37
High-level control flow
These jumps and branches are much simpler than the control flow constructs provided by high-level languages. Conditional statements execute only if some Boolean value is true. Loops cause some statements to be executed many times // Find the absolute value of *X R1 = *X; if (R1 < 0) R1 = -R1; // This might not be executed R3 = R1 + R1; // Sum the integers from 1 to 5 R1 = 0; for (R2 = 1; R2 <= 5; R2++) R1 = R1 + R2; // This is executed five times R3 = R1 + R1; 11/24/2018 Datapaths
38
Translating the C if-then statement
We can use branch instructions to translate high-level conditional statements into assembly code. Sometimes it’s easier to invert the original condition. Here, we effectively changed the R1 < 0 test into R1 >= 0. R1 = *X; if (R1 < 0) R1 = -R1; R3 = R1 + R1; LD R1, (X) // R1 = *X BNN R1, L // Skip MUL if R1 is not negative MUL R1, R1, #-1 // R1 = -R1 L ADD R3, R1, R1 // R3 = R1 + R1 11/24/2018 Datapaths
39
Translating the C for loop
Here is a translation of the for loop, using a hypothetical BGT branch. R1 = 0; for (R2 = 1; R2 <= 5; R2++) R1 = R1 + R2; R3 = R1 + R1; LD R1, #0 // R1 = 0 LD R2, #1 // R2 = 1 FOR BGT R2, #5, L // Stop when R2 > 5 ADD R1, R1, R2 // R1 = R1 + R2 ADD R2, R2, #1 // R2++ JMP FOR // Go back to the loop test L ADD R3, R1, R1 // R3 = R1 + R1 11/24/2018 Datapaths
40
Summary Machine language is the interface between software and processors. High-level programs must be translated into machine language before they can be run. There are three main categories of instructions. Data manipulation operations, such as adding or shifting Data transfer operations to copy data between registers and RAM Control flow instructions to change the execution order Instruction set architectures depend highly on the host CPU’s design. Today we saw instructions that would be appropriate for our datapath from last week. On Wednesday we’ll look at some other possibilities. 11/24/2018 Datapaths
41
Instruction encoding We’ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers use instruction sets to issue commands. Now let’s complete our processor with a control unit that converts assembly language instructions into datapath signals. Today we’ll see how control units fit into the big picture, and how assembly instructions can be represented in a binary format. On Wednesday we’ll show all of the implementation details for our sample datapath and assembly language. July 23, 2002 © Howard Huang
42
Block diagram of a processor
The control unit connects programs with the datapath. It converts program instructions into control words for the datapath, including signals WR, DA, AA, BA, MB, FS, MW, MD. It executes program instructions in the correct sequence. It generates the “constant” input for the datapath. The datapath also sends information back to the control unit. For instance, the ALU status bits V, C, N, Z can be inspected by branch instructions to alter a program’s control flow. Program Control signals Control Unit Datapath Status signals 11/24/2018 Datapaths
43
A specific instruction set
The first thing we must do is agree upon an instruction set. For our example CPU let’s stick with the three-address, register-to-register instruction set architecture introduced yesterday. Data manipulation instructions have one destination and up to two sources, which must be either registers or constants. We include dedicated load and store instructions to transfer data to and from memory. Next Monday, we’ll learn about different kinds of instruction sets. 11/24/2018 Datapaths
44
From assembly to machine language
Next, we must define a machine language, or a binary representation of the assembly instructions that our processor supports. Our CPU includes three types of instructions, which have different operands and will need different representations. Register format instructions require two source registers. Immediate format instructions have one source register and one constant operand. Jump and branch format instructions need one source register and one constant address. Even though there are three different instruction formats, it is best to make their binary representations as similar as possible. This will make the control unit hardware simpler. We’ll start by making all of our instructions 16 bits long. 11/24/2018 Datapaths
45
Register format An example register-format instruction: ADD R1, R2, R3
An example register-format instruction: ADD R1, R2, R3 Our binary representation for these instructions will include: A 7-bit opcode field, specifying the operation (e.g., ADD). A 3-bit destination register, DR. Two 3-bit source registers, SA and SB. 11/24/2018 Datapaths
46
Immediate format An example immediate-format instruction:
An example immediate-format instruction: ADD R1, R2, #3 Immediate-format instructions will consist of: A 7-bit instruction opcode. A 3-bit destination register, DR. A 3-bit source register, SA. A 3-bit constant operand, OP. 11/24/2018 Datapaths
47
PC-relative jumps and branches
We will use PC-relative addressing for jumps and branches, where the operand specifies the number of addresses to jump or branch from the current instruction. We can assume each instruction occupies one word of memory. The operand is a signed number. It’s possible to jump or branch either “forwards” or “backwards.” Backward jumps are often used to implement loops; see some of the examples from last week. LD R1, # LD R1, #10 LD R2, # LD R2, #3 JMP L 1002 JMP 2 K LD R1, # LD R1, #20 LD R2, # LD R2, #4 L ADD R3, R3, R ADD R3, R3, R2 ST (R1), R ST (R1), R3 11/24/2018 Datapaths
48
Jump and branch format Two example jump and branch instructions:
Two example jump and branch instructions: BZ R3, -24 JMP 18 Jump and branch format instructions include: A 7-bit instruction opcode. A 3-bit source register SA for branch conditions. A 6-bit address field, AD, for storing jump or branch offsets. Our branch instructions support only one source register. Other types of branches can be simulated from these basic ones. 11/24/2018 Datapaths
49
The address field AD AD is treated as a six-bit signed number, so you can branch up to 31 addresses forward (25-1), or up to 32 addresses backward (-25). The address field is split into two parts for uniformity, so the SA field occupies the same position in all three instruction formats. 11/24/2018 Datapaths
50
Instruction format uniformity
Notice the similarities between the different instruction formats. The Opcode field always appears in the same position (bits 15-9). DR is in the same place for register and immediate instructions. The SA field also appears in the same position, even though this forced us to split AD into two parts for jumps and branches. Tomorrow we’ll see how this leads to a simpler control unit. 11/24/2018 Datapaths
51
Instruction formats and the datapath
The instruction format and datapath are inter-related. Since register addresses (DR, SA and SB) are three bits each, this instruction set can only support eight registers. The constant operand (OP) is also three bits long. Its value will have to be sign-extended if the ALU supports wider inputs and outputs. Conversely, supporting more registers or larger constants would require us to increase the length of our machine language instructions. 11/24/2018 Datapaths
52
Organizing our instructions
How can we select binary opcodes for each possible operation? In general, “similar” instructions should have similar opcodes. Again, this will lead to simpler control unit hardware. We can divide our instructions into eight different categories, each of which require similar datapath control signals. To show the similarities within categories, we’ll look at register-based ALU operations and memory write operations in detail. 11/24/2018 Datapaths
53
Register format ALU operations
ADD R1, R2, R3 All register format ALU operations need the same values for the following control signals: MB = 0, because all operands come from the register file. MD = 0 and WR = 1, to save the ALU result back into a register. MW = 0 since RAM is not modified. WR 1 D Register file A B DA AA BA A B ALU G FS V C N Z Mux B MB Mux D MD ADRS DATA Data RAM OUT MW constant 11/24/2018 Datapaths
54
Memory write operations
ST (R0), R1 All memory write operations need the same values for the following control signals: MB = 0, because the data to write comes from the register file. MD = X and WR = 0, since none of the registers are changed. MW = 1, to update RAM. WR D Register file A B DA AA BA A B ALU G FS V C N Z Mux B MB Mux D MD X ADRS DATA Data RAM OUT MW 1 constant 11/24/2018 Datapaths
55
Selecting opcodes Instructions in each of these categories are similar, so it would be convenient if those instructions had similar opcodes. We’ll assign opcodes so that all instructions in the same category will have the same first three opcode bits (bits of the instruction). Next time we’ll talk about the other instruction categories shown here. 11/24/2018 Datapaths
56
ALU and shift instructions
What about the rest of the opcode bits? For ALU and shift operations, let’s fill in bits 12-9 of the opcode with FS3-FS0 of the five-bit ALU function select code. For example, a register-based XOR instruction would have the opcode The first three bits 000 indicate a register-based ALU instruction. 1100 denotes the ALU XOR function. An immediate shift left instruction would have the opcode 101 indicates an immediate shift. 1000 denotes a shift left. 11/24/2018 Datapaths
57
Branch instructions We’ll implement branch instructions for the eight different conditions shown here. Bits 11-9 of the opcode field will indicate the type of branch. (We only need three bits to select one of eight branches, so opcode bit 12 won’t be needed.) For example, the branch if zero instruction BZ would have the opcode 110x011. The first three bits 110 indicate a branch. 011 specifies branch if zero. 11/24/2018 Datapaths
58
Sample opcodes Here are some more examples of instructions and their corresponding opcodes in our instruction set. Several opcodes have unused bits. We only need three bits to distinguish eight types of branches. There is only one kind of jump and one kind of load instruction. These unused opcodes allow for future expansion of the instruction set. For instance, we might add new instructions or new addressing modes. 11/24/2018 Datapaths
59
Sample instructions Here are complete translations of the instructions. The meaning of bits 8-0 depends on the instruction format. The colors are not supposed to blind you, but to help you distinguish between destination, source, constant and address fields. 11/24/2018 Datapaths
60
Summary Today we defined a binary machine language for the instruction set from yesterday. Different instructions have different operands and formats, but keeping the formats uniform will help simplify our hardware. We also try to assign similar opcodes to “similar” instructions. The instruction encodings and datapath are closely related. For example, our opcodes include ALU selection codes, and the number of available registers is limited by the size of each instruction. This is just one example of how to define a machine language. You will be using a different instruction encoding for MP4, for instance. On Wednesday we’ll show how to build a control unit corresponding to our datapath and instruction set. This will complete our processor! 11/24/2018 Datapaths
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.