DOC PREVIEW
U of I CS 231 - Instruction encoding

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Instruction encoding 1Instruction 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.Instruction encoding 2Review: Datapath• 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 movementinstructions to transfer data between the RAM and the register file.D dataWriteD addressA address B addressA data B dataRegister FileWRDAAA BAQ D1D0SRAMADRSDATACSWROUTMW+5VA BALUFZNCVFSFSMDS D1 D0QConstantMBInstruction encoding 3Block 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.ControlUnitDatapathControl signalsStatus signalsProgramInstruction encoding 4A 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 in the last lecture.– 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 week, we’ll learn about different kinds of instruction sets.Instruction encoding 5From 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.Instruction encoding 6Register format• 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.OpcodeDestinationRegister(DR)SourceRegister A(SA)SourceRegister B(SB)15 9 8 6 5 3 2 0Instruction encoding 7Immediate format• 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.OpcodeDestinationRegister(DR)SourceRegister A(SA)Operand(OP)15 9 8 6 5 3 2 0Instruction encoding 8• 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 signednumber.– 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, #10 1000 LD R1, #10LD R2, #3 1001 LD R2, #3JMP L 1002 JMP 2K LD R1, #20 1003 LD R1, #20LD R2, #4 1004 LD R2, #4L ADD R3, R3, R2 1005 ADD R3, R3, R2ST (R1), R3 1006 ST (R1), R3PC-relative jumps and branchesInstruction encoding 9Jump and branch format• 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.OpcodeAddressBits 5-3(AD)SourceRegister A(SA)AddressBits 2-0(AD)15 9 8 6 5 3 2 0Instruction encoding 10The 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.OpcodeAddressBits 5-3(AD)SourceRegister A(SA)AddressBits 2-0(AD)15 9 8 6 5 3 2 0Instruction encoding 11Instruction 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 thisforced us to split AD into two parts for jumps and branches.• Next lecture, we’ll see how this leads to a simpler control unit.OpcodeDestinationRegister(DR)SourceRegister A(SA)SourceRegister B(SB)15 9 8 6 5 3 2 0OpcodeDestinationRegister(DR)SourceRegister A(SA)Operand(OP)OpcodeAddressBits 5-3(AD)SourceRegister A(SA)AddressBits 2-0(AD)Instruction encoding 12Instruction 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


View Full Document

U of I CS 231 - Instruction encoding

Documents in this Course
Counters

Counters

23 pages

Latches

Latches

22 pages

Lecture

Lecture

33 pages

Lecture

Lecture

16 pages

Lecture

Lecture

4 pages

Datapaths

Datapaths

30 pages

Lecture

Lecture

6 pages

Registers

Registers

17 pages

Datapaths

Datapaths

28 pages

Decoders

Decoders

20 pages

Load more
Download Instruction encoding
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Instruction encoding and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Instruction encoding 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?