Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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:

1 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

2 CML CMLAnnouncements Project 3 –Due October 19, 2009 Midterm –Thursday, October 22, 2009 –Contents MIPS ISA and Programming Function calls and register conventions Assembling MIPS Instructions 2’s complement number system FP number system Finals –Tuesday, Dec 08, 2009

3 CML CML Computer Organization We have leaned the ISA of the processor till now –Given an algorithm, express it in terms of the processor ISA Instruction Set Architecture software hardware

4 CML CML  High-level language program (in C) swap (int v[], int k)...  Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31  Machine (object) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Below the Program C - Compiler Assembler

5 CML CML Working of Computer Processor Control Datapath Memory Devices Input Output

6 CML CML Input Device Inputs Object Code Processor Control Datapath Memory Devices Input Output 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000

7 CML CML Object Code Stored in Memory Processor Control Datapath Memory Devices Input Output 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000

8 CML CML Processor Fetches an Instruction Processor Fetches an Instruction Processor Control Datapath Memory Devices Input Output 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Processor fetches an instruction from memory

9 CML CML Control 000000 00100 00010 0001000000100000 Control Decodes the Instruction Control Decodes the Instruction Processor Datapath Memory Devices Input Output Control decodes the instruction to determine what to execute

10 CML CML Datapath Executes the Instruction Processor Control Datapath Memory Devices Input Output contents Reg #4 ADD contents Reg #2 results put in Reg #2 Datapath executes the instruction as directed by control 000000 00100 00010 0001000000100000

11 CML CML Update the PC, and continue Processor Control Datapath Memory Devices Input Output 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000 100011 00010 01111 0000000000000000 100011 00010 10000 0000000000000100 101011 00010 10000 0000000000000000 101011 00010 01111 0000000000000100 000000 11111 00000 0000000000001000 Fetch DecodeExecute

12 CML CML Output Data Stored in Memory Processor Control Datapath Memory Devices Input Output 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000 At program completion the data to be output resides in memory

13 CML CML Output Device Outputs Data Processor Control Datapath Memory Devices Input Output 00000100010100000000000000000000 00000000010011110000000000000100 00000011111000000000000000001000

14 CML CML MIPS ISA to Implement Arithmetic Instructions –Add, sub, AND, OR, and slt (R-type) Memory access instructions –LW, and SW (I-type) Branch instructions –Beq(I-type) Jump instructions –J(J-type)

15 CML CML MIPS Machine Read Address Instr[31-0] Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data 2 ALU ovf zero RegWrite Data Memory Address Write Data Read Data MemWrite MemRead Sign Extend 1632 MemtoReg ALUSrc Shift left 2 Add PCSrc RegDst ALU control 1 1 1 0 0 0 0 1 ALUOp Instr[5-0] Instr[15-0] Instr[25-21] Instr[20-16] Instr[15 -11] Control Unit Instr[31-26] Branch Shift left 2 0 1 Jump 32 Instr[25-0] 26 PC+4[31-28] 28

16 CML CML Build a MIPS Processor Today – Build the ALU –Support all the Arithmetic/Logic operations 32 ALU control lines result a b ALU ALU Control LinesFunction 0000AND 0001OR 0010add 0110subtract 0111Set on less than 1100NOR

17 CML CML ALUOp and ALU control bits Instruction Opcode ALUOpInstruction operation Funct field Desired ALU action ALU control input LW00Load wordXXXXXXadd0010 SW00Store wordXXXXXXAdd0010 Beq01Branch equalXXXXXXSubtract0110 R-type10Add100000Add0010 R-type10Subtract100010Subtract0110 R-type10AND100100AND0000 R-type10OR100101OR0001 R-type10Set on less than101010Set on less than0111

18 CML CMLImplementation Truth table for 4 ALU control bits

19 CML CML Building a 1-bit Binary Adder S = A xor B xor carry_in carry_out = (A and B) or (A and carry_in) or (B and carry_in) 1 bit Full Adder A B S carry_in carry_out How can we use it to build a 32-bit adder? How can we modify it easily to build an adder/subtractor? ABcarry_incarry_outS 00000 00101 01001 01110 10001 10110 11010 11111

20 CML CML Building 32-bit Adder Just connect the carry-out of the least significant bit FA to the carry-in of the next least significant bit and connect... Ripple Carry Adder (RCA) –advantage: simple logic, so small (low cost) –disadvantage: slow and lots of glitching (so lots of energy consumption) 1-bit FA A0A0 B0B0 S0S0 c 0 =carry_in c1c1 1-bit FA A1A1 B1B1 S1S1 c2c2 A2A2 B2B2 S2S2 c3c3 c 32 =carry_out 1-bit FA A 31 B 31 S 31 c 31...

21 CML CML Building 32-bit Adder/Subtractor Remember 2’s complement is just –complement all the bits –add a 1 in the least significant bit A 0111  0111 B - 0110  + 1010 1-bit FA S0S0 c 0 =carry_in c1c1 1-bit FA S1S1 c2c2 S2S2 c3c3 c 32 =carry_out 1-bit FA S 31 c 31... A0A0 A1A1 A2A2 A 31 B0B0 B1B1 B2B2 B 31 add/subt B0B0 control (0=add,1=subt) B 0 if control = 0, !B 0 if control = 1

22 CML CML Logic Operations Logic operations operate on individual bits of the operand. $t2 = 0…0 0000 1101 0000 $t1 = 0…0 0011 1100 0000 and $t0, $t1, $t2$t0 = or $t0, $t1, $t2$t0 = xor $t0, $t1, $t2$t0 = nor $t0, $t1, $t2$t0 = How do we expand our FA design to handle the logic operations - and, or, xor, nor ? 0…0 0000 1100 0000 0…0 0011 1101 0000 0…0 0011 0001 0000 1…1 1100 0010 1111

23 CML CML A Simple ALU Cell 1-bit FA carry_in carry_out A B add/subt result op

24 CML CML Tailoring the ALU to the MIPS ISA Need to support the set-on-less-than instruction ( slt ) –remember: slt is an arithmetic instruction –produces a 1 if rs < rt and 0 otherwise –use subtraction: (a - b) < 0 implies a < b Need to support test for equality ( beq ) –use subtraction: (a - b) = 0 implies a = b Need to add the overflow detection hardware

25 CML CML Modifying the ALU Cell for slt 1-bit FA A B result carry_in carry_out add/subtop add/subt less

26 CML CML ALU for slt 0 0 set  First perform a subtraction  Make the result 1 if the subtraction yields a negative result  Make the result 0 if the subtraction yields a positive result tie the most significant sum bit (sign bit) to the low order less input

27 CML CML ALU for Zero + A1A1 B1B1 result 1 less + A0A0 B0B0 result 0 less + A 31 B 31 result 31 less... 0 0 set  First perform subtraction  Insert additional logic to detect when all result bits are zero zero... add/subt op Note zero is a 1 when result is all zeros

28 CML CML Overflow Detection Overflow: the result is too large to represent in the number of bits allocated On your own: Prove you can detect overflow by: –Carry into MSB xor Carry out of MSB 1 1 11 0 1 0 1 1 0 0111 0011+ 7 3 0 1 – 6 1100 1011+ –4 – 5 7 1 0

29 CML CML Modifying the ALU for Overflow + A1A1 B1B1 result 1 less + A0A0 B0B0 result 0 less + A 31 B 31 result 31 less... 0 0 set  Modify the most significant cell to determine overflow output setting  Disable overflow bit setting for unsigned arithmetic zero... add/subt op overflow

30 CML CML Shift Operations Also need operations to pack and unpack 8-bit characters into 32- bit words Shifts move all the bits in a word left or right sll $t2, $s0, 8 #$t2 = $s0 << 8 bits srl $t2, $s0, 8 #$t2 = $s0 >> 8 bits Such shifts are logical because they fill with zeros op rs rt rd shamt funct 000000 00000 10000 01010 01000 000000 000000 00000 10000 01010 01000 000010

31 CML CML Shift Operations An arithmetic shift ( sra ) maintain the arithmetic correctness of the shifted value (i.e., a number shifted right one bit should be ½ of its original value; a number shifted left should be 2 times its original value) –so sra uses the most significant bit (sign bit) as the bit shifted in –note that there is no need for a sla when using two’s complement number representation sra $t2, $s0, 8 #$t2 = $s0 >> 8 bits The shift operation is implemented by hardware (usually a barrel shifter) outside the ALU 000000 00000 10000 01010 01000 000011

32 CML CML MIPS Machine Read Address Instr[31-0] Instruction Memory Add PC 4 Write Data Read Addr 1 Read Addr 2 Write Addr Register File Read Data 1 Read Data 2 ALU ovf zero RegWrite Data Memory Address Write Data Read Data MemWrite MemRead Sign Extend 1632 MemtoReg ALUSrc Shift left 2 Add PCSrc RegDst ALU control 1 1 1 0 0 0 0 1 ALUOp Instr[5-0] Instr[15-0] Instr[25-21] Instr[20-16] Instr[15 -11] Control Unit Instr[31-26] Branch Shift left 2 0 1 Jump 32 Instr[25-0] 26 PC+4[31-28] 28

33 CML CML Yoda says… Use your feelings, Obi-Wan, and find him you will


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

Similar presentations


Ads by Google