Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (www.cse.psu.edu/~mji)

Similar presentations


Presentation on theme: "CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (www.cse.psu.edu/~mji)"— Presentation transcript:

1 CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (www.cse.psu.edu/~mji) which in turn Adapted from Computer Organization and Design,www.cse.psu.edu/~mji Patterson & Hennessy, © 2005, UCB]

2 CPE 232 MIPS Arithmetic2  32-bit signed numbers (2’s complement): 0000 0000 0000 0000 0000 0000 0000 0000 two = 0 ten 0000 0000 0000 0000 0000 0000 0000 0001 two = + 1 ten... 0111 1111 1111 1111 1111 1111 1111 1110 two = + 2,147,483,646 ten 0111 1111 1111 1111 1111 1111 1111 1111 two = + 2,147,483,647 ten 1000 0000 0000 0000 0000 0000 0000 0000 two = – 2,147,483,648 ten 1000 0000 0000 0000 0000 0000 0000 0001 two = – 2,147,483,647 ten... 1111 1111 1111 1111 1111 1111 1111 1110 two = – 2 ten 1111 1111 1111 1111 1111 1111 1111 1111 two = – 1 ten MIPS Number Representations maxint minint  Converting <32-bit values into 32-bit values copy the most significant bit (the sign bit) into the “empty” bits 0010 -> 0000 0010 1010 -> 1111 1010 sign extend versus zero extend ( lb vs. lbu ) MSB LSB

3 CPE 232 MIPS Arithmetic3 MIPS Arithmetic Logic Unit (ALU)  Must support the Arithmetic/Logic operations of the ISA add, addi, addiu, addu sub, subu, neg mult, multu, div, divu sqrt and, andi, nor, or, ori, xor, xori beq, bne, slt, slti, sltiu, sltu 32 m (operation) result A B ALU 4 zeroovf 1 1  With special handling for sign extend – addi, addiu andi, ori, xori, slti, sltiu zero extend – lbu, addiu, sltiu no overflow detected – addu, addiu, subu, multu, divu, sltiu, sltu

4 CPE 232 MIPS Arithmetic4 Review: 2’s Complement Binary Representation 2’sc binarydecimal 1000-8 1001-7 1010-6 1011-5 1100-4 1101-3 1110-2 1111 00000 00011 00102 00113 01004 01015 01106 01117 2 3 - 1 = -(2 3 - 1) = -2 3 = 1010 complement all the bits 1011 and add a 1  Note: negate and invert are different!  Negate

5 CPE 232 MIPS Arithmetic5 Binary Addition

6 CPE 232 MIPS Arithmetic6 Review: A Full Adder 1-bit Full Adder A B S carry_in carry_out S = A  B  carry_in (odd parity function) carry_out = A&B | A&carry_in | B&carry_in (majority function)  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

7 CPE 232 MIPS Arithmetic7 A 32-bit Ripple Carry 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  + 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/sub B0B0 control (0=add,1=sub) B 0 if control = 0, !B 0 if control = 1 0001 1001 1 1 0001

8 CPE 232 MIPS Arithmetic8 Overflow Detection  Overflow: the result is too large to represent in 32 bits  Overflow occurs when l adding two positives yields a negative l or, adding two negatives gives a positive l or, subtract a negative from a positive gives a negative l or, subtract a positive from a negative gives a positive  On your own: Prove you can detect overflow by: l Carry into MSB xor Carry out of MSB, ex for 4 bit signed numbers 1 1 11 0 1 0 1 1 0 0111 0011+ 7 3 0 1 – 6 1100 1011+ –4 – 5 7 1 0

9 CPE 232 MIPS Arithmetic9  Need to support the logic operations ( and,nor,or,xor ) l Bit wise operations (no carry operation involved) l Need a logic gate for each function, mux to choose the output  Need to support the set-on-less-than instruction ( slt ) l Use subtraction to determine if (a – b) < 0 (implies a < b) l Copy the sign bit into the low order bit of the result, set remaining result bits to 0  Need to support test for equality ( bne, beq ) l Again use subtraction: (a - b) = 0 implies a = b l Additional logic to “nor” all result bits together  Immediates are sign extended outside the ALU with wiring (i.e., no logic needed) Tailoring the ALU to the MIPS ISA

10 CPE 232 MIPS Arithmetic10 MIPS ALU  Least-significant bits FunctionBnegateOperation and000 or001 add010 sub110 slt111

11 CPE 232 MIPS Arithmetic11 MIPS ALU  Most-significant bit FunctionBnegateOperation and000 or001 add010 sub110 slt111

12 CPE 232 MIPS Arithmetic12 MIPS ALU

13 CPE 232 MIPS Arithmetic13 Improving Addition Performance  The ripple-carry adder is slow

14 CPE 232 MIPS Arithmetic14 Carry-Lookahead Adder  Need fast way to find the carry

15 CPE 232 MIPS Arithmetic15 Carry-Lookahead Adder  Carry generate and carry propagate  g i = a i. b i  p i = a i + b i aiai bibi gigi pipi 0000 0101 1001 1111

16 CPE 232 MIPS Arithmetic16 Carry-Lookahead Adder Carry Equations: c1 = g0 + p0c0 c2 = g1 + p1c1 = g1 + p1g0 + p1p0c0 c3 = g2 + p2c2 = g2 + p2g1 + p2p1g0 + p2p1p0c0 c4 = g3 + p3c3 = g3 + p3g2 + p3p2g1 + p3p2p1g0 + p3p2p1p0c0

17 CPE 232 MIPS Arithmetic17 4-bit Carry-Lookahead Adder

18 CPE 232 MIPS Arithmetic18 Larger Carry-Lookahead Adders P = p0p1p2p3 G = g3 + g2p3 + g1p2p3 + g0p1p2p3


Download ppt "CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (www.cse.psu.edu/~mji)"

Similar presentations


Ads by Google