DOC PREVIEW
U of I CS 231 - Instruction encoding

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 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 24 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 24 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 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Instruction encodingTranslating the C if-then statementTranslating the C for loopSummary of ISAReview: DatapathBlock diagram of a processorA specific instruction setFrom assembly to machine languageRegister formatImmediate formatPC-relative jumps and branchesJump and branch formatThe address field ADInstruction format uniformityInstruction formats and the datapathOrganizing our instructionsRegister format ALU operationsMemory write operationsSelecting opcodesALU and shift instructionsBranch instructionsSample opcodesSample instructionsSummary01/14/19 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.01/14/19 Instruction encoding 2•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.Translating the C if-then statementR1 = *X;if (R1 < 0)R1 = -R1;R3 = R1 + R1;LD R1, (X) // R1 = *XBNN R1, L // Skip MUL if R1 is not negativeLD R2,#0SUB R1, R2, R1 // R1 = 0-R1L ADD R3, R1, R1 // R3 = R1 + R101/14/19 Instruction encoding 3Translating the C for loop•Here is a translation of the for loop, using a hypothetical BGT branch.LD R1, #0 // R1 = 0LD R2, #1 // R2 = 1FOR BGT R2, #5, L // Stop when R2 > 5ADD R1, R1, R2 // R1 = R1 + R2ADD R2, R2, #1 // R2++JMP FOR // Go back to the loop testL ADD R3, R1, R1 // R3 = R1 + R1R1 = 0;for (R2 = 1; R2 <= 5; R2++)R1 = R1 + R2;R3 = R1 + R1;01/14/19 Instruction encoding 4Summary of ISA•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.01/14/19 Instruction encoding 5Review: 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 movement instructions to transfer data between the RAM and the register file.D data Write D address A address B addressA data B dataRegister FileWRDAAA BAQ D1 D0 S RAM ADRS DATA CS WROUTMW+5VA BALUFZNCVFSFS MDS D1 D0 Q Constant MB01/14/19 Instruction encoding 6Block 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 signalsProgram01/14/19 Instruction encoding 7A 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.01/14/19 Instruction encoding 8From 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.01/14/19 Instruction encoding 9Register 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 001/14/19 Instruction encoding 10Immediate 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 001/14/19 Instruction encoding 11•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, #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


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?