# CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.

## Presentation on theme: "CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics."— Presentation transcript:

CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics Arizona State University Slides courtesy: Prof. Yann Hang Lee, ASU, Prof. Mary Jane Irwin, PSU, Ande Carle, UCB

CML CMLAnnouncements Project 3 –MIPS Assembler Midterm Reviews Quiz 4 –Nov 5, 2009 –Single-cycle implementation Finals –Tuesday, Dec 08, 2009

CML CML What is this? 00100111101111011111111111100000 10101111101111110000000000010100 10101111101001000000000000100000 10101111101001010000000000100100 10101111101000000000000000011000 10101111101000000000000000011100 10001111101011100000000000011100 10001111101110000000000000011000 00000001110011100000000000011001 00100101110010000000000000000001 00101001000000010000000001100101 10101111101010000000000000011100 00000000000000000111100000010010 00000011000011111100100000100001 00010100001000001111111111110111 10101111101110010000000000011000 00111100000001000001000000000000 10001111101001010000000000011000 00001100000100000000000011101100 00100100100001000000010000110000 10001111101111110000000000010100 00100111101111010000000000100000 00000011111000000000000000001000 00000000000000000001000000100001 MIPS machine language code for a routine to compute and print the sum of the squares of integers between 0 and 100. int main (int argc, char *argv[]) { int i; int sum = 0; for (i = 0; i <= 100; i = i + 1) sum = sum + i * i; printf ("The sum from 0.. 100 is %d\n", sum); }

CML CML Abstract Implementation View Two types of functional units: –elements that operate on data values (combinational) –elements that contain state (sequential) Single cycle operation Split memory (Harvard) model - one memory for instructions and one for data AddressInstruction Memory Write Data Reg Addr Register File ALU Data Memory Address Write Data Read Data PC Read Data Read Data

CML CML Fetching Instructions Fetching instructions involves –reading the instruction from the Instruction Memory –updating the PC to hold the address of the next instruction –PC is updated every cycle, so it does not need an explicit write control signal –Instruction Memory is read every cycle, so it doesn’t need an explicit read control signal Read Address Instruction Memory Add PC 4

CML CML Executing R Format Operations R format operations ( add, sub, slt, and, or ) –perform the indicated (by op and funct) operation on values in rs and rt –store the result back into the Register File (into location rd) –Note that Register File is not written every cycle (e.g. sw ), so we need an explicit write control signal for the Register File Instruction Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data 2 ALU overflow zero ALU controlRegWrite R-type: 3125201550 oprsrtrdfunctshamt 10

CML CML Executing Jump Operations Jump operations have to –replace the lower 28 bits of the PC with the lower 26 bits of the fetched instruction shifted left by 2 bits Read Address Instruction Memory Shift left 2 Jump address 26 4 28 J-Type: op 31250 jump target address Add 4 PC

CML ALU Control ALU control inputFunction 000and 001or 010add 110subtract 111set on less than  ALU's operation based on instruction type and function code result 32 operation a b ALU

CML ALU Control Controlling the ALU makes use of multiple levels of decoding –main control unit generates the ALUOp bits –ALU control unit generates ALU control inputs Instr opopcodefunctALUOpdesired action ALU control input lw23xxxxxx00add010 sw2bxxxxxx00add010 beq4xxxxxx01subtract110 add010000010add010 subt010001010subtract110 and010010010and000 or010010110or001 slt010101010slt111

CML ALU Control Truth Table Can make use of more don’t cares –since ALUOp does not use the encoding 11 –since F5 and F4 are always 10 Logic comes from the K-maps … X X X X X X F5F4F3F2F1F0ALUOp1ALUOp0Op2Op1Op0 XXXXXX00010 XXXXXX1110 XX00001010 XX00101110 XX01001000 XX01011001 XX10101111

CML CML ALU Control Combinational Logic From the truth table can design the ALU Control logic

CML CML Main Control Unit InstrRegDstALUSrcMemtoRegRegWrMemRdMemWrBranchALUOp1ALUOp2 R-type 000000 lw 100011 sw 101011 beq 000100  Completely determined by the instruction opcode field l Note that a multiplexor whose control input is 0 has a definite action, even if it is not used in performing the operation

CML CML Main Control Unit InstrRegDstALUSrcMemtoRegRegWrMemRdMemWrBranchALUOp1ALUOp0 R-type 000000 1001X001X lw 100011 sw 101011 beq 000100

CML CML Main Control Unit InstrRegDstALUSrcMemtoRegRegWrMemRdMemWrBranchALUOp1ALUOp0 R-type 000000 1001X001X lw 100011 011110000 sw 101011 beq 000100

CML CML Main Control Unit InstrRegDstALUSrcMemtoRegRegWrMemRdMemWrBranchALUOp1ALUOp0 R-type 000000 1001X001X lw 100011 011110000 sw 101011 X1X0X1000 beq 000100

CML CML Main Control Unit Completely determined by the instruction opcode field –Note that a multiplexor whose control input is 0 has a definite action, even if it is not used in performing the operation InstrRegDstALUSrcMemtoRegRegWrMemRdMemWrBranchALUOp1ALUOp0 R-type 000000 1001X001X lw 100011 011110000 sw 101011 X1X0X1000 beq 000100 X0X0X01X1

CML CML Control Unit Logic From the truth table can design the Main Control logic Instr[31] Instr[30] Instr[29] Instr[28] Instr[27] Instr[26] R-type lwswbeq RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOp0