Arithmetic Structures ECE 352 Digital System Fundamentals Arithmetic

  • Slides: 23
Download presentation
Arithmetic Structures ECE 352 Digital System Fundamentals Arithmetic Structures 1

Arithmetic Structures ECE 352 Digital System Fundamentals Arithmetic Structures 1

Topics Arithmetic Structures • 2 Arithmetic Structures • • • Addition and Subtraction Contraction

Topics Arithmetic Structures • 2 Arithmetic Structures • • • Addition and Subtraction Contraction and Specialized Structures Other Arithmetic Operations

Review: Binary Addition Arithmetic Structures • 3 • Same operation at every bit position:

Review: Binary Addition Arithmetic Structures • 3 • Same operation at every bit position: • • Add two bits plus carry-in if present If result larger than representable by one bit, carry-out from that position How should we create hardware for this? • • Design hardware for one bit position Replicate!

Review: Half/Full Adders Arithmetic Structures • • • 4 Half Adder • Adds two

Review: Half/Full Adders Arithmetic Structures • • • 4 Half Adder • Adds two single-bit inputs Full Adder • • Adds three single-bit inputs Built from two half-adders plus an OR gate Need a full adder to propagate the carry!

Ripple Carry Adder Arithmetic Structures • 5 • Combinational circuit to add two binary

Ripple Carry Adder Arithmetic Structures • 5 • Combinational circuit to add two binary vectors • In an n-bit number the LSb has subscript 0 and the MSb has subscript n-1 Series of Full Adders • A carry can occur at any bit position and ripple through towards the most significant bit. the carry-out of each full adder is the carry-in to the next

Binary Subtractor Arithmetic Structures • Modify ripple-carry adder: A + (–B) • • Bitwise

Binary Subtractor Arithmetic Structures • Modify ripple-carry adder: A + (–B) • • Bitwise complement B before the addition Add the 1 to B using the carry-in “flip all the bits” “and add 1” 6

Adder/Subtractor Arithmetic Structures • • Use the same structure to both add and subtract

Adder/Subtractor Arithmetic Structures • • Use the same structure to both add and subtract • • • If we want to add, don’t negate If we want to subtract, negate: “Flip all the bits and add 1” Augment the structure with additional logic and a special control signal • • 7 Conditionally negate the second operand Control input to the adder/subtractor chooses the mode of operation Depending on its value, the structure adds or subtracts

Binary Adder-Subtractor Arithmetic Structures • 8 Subtract if SUB is 1, add if SUB

Binary Adder-Subtractor Arithmetic Structures • 8 Subtract if SUB is 1, add if SUB is 0 • • XOR it with all bits of second operand • “Flip all the bits IF we want to subtract (but do not if we add)” Use it as the carry input • “Add 1 IF we want to subtract (but not if we add)”

Overflow Detection • We know we have overflow if the result cannot “fit” in

Overflow Detection • We know we have overflow if the result cannot “fit” in the required number of bits Arithmetic Structures • 9 • • But how can we automatically detect this? Unsigned overflow if C = 1 • Cout of MSb is 1 Signed overflow if V = 1 • Cin to MSb does not match Cout from MSb

Topics Arithmetic Structures • 10 Arithmetic Structures • • • Addition and Subtraction Contraction

Topics Arithmetic Structures • 10 Arithmetic Structures • • • Addition and Subtraction Contraction and Specialized Structures Other Arithmetic Operations

Contraction Arithmetic Structures • • • 11 If an input to a circuit will

Contraction Arithmetic Structures • • • 11 If an input to a circuit will always be a constant value, we can simplify the circuit Apply Boolean algebra rules to reduce and/or remove gates Contraction makes the circuit smaller, faster, and less complex (more efficient for a specific task)

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should assume “increment” means “add 1” Simplified adder structure • Set the B input to 0012, then simplify 0 0 12

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should assume “increment” means “add 1” Simplified adder structure • Set the B input to 0012, then simplify inverter 0 0 13 0

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should assume “increment” means “add 1” Simplified adder structure • Set the B input to 0012, then simplify 0 0 0 14

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should

Example: Incrementer Arithmetic Structures • • Note: if an amount is not specified, should assume “increment” means “add 1” Simplified adder structure • Set the B input to 0012, then simplify 0 0 15

Example: Incrementer Arithmetic Structures • 16 • Note: if an amount is not specified,

Example: Incrementer Arithmetic Structures • 16 • Note: if an amount is not specified, should assume “increment” means “add 1” Simplified adder structure • Set the B input to 0012, then simplify We can also remove AND gate if the carry-out is not needed

Example: Decrement-by-two Arithmetic Structures • “Decrement by two” means add − 2 • •

Example: Decrement-by-two Arithmetic Structures • “Decrement by two” means add − 2 • • Set the B input to 1102, then simplify We could use adder/subtractor in subtract mode and use B = 0102, but that requires more simplification! 1 1 0 0 17

Example: Decrement-by-two Arithmetic Structures • “Decrement by two” means add − 2 • •

Example: Decrement-by-two Arithmetic Structures • “Decrement by two” means add − 2 • • Set the B input to 1102, then simplify We could use adder/subtractor in subtract mode and use B = 0102, but that requires more simplification! 1 1 0 18

Example: Decrement-by-two Arithmetic Structures • 19 “Decrement by two” means add − 2 •

Example: Decrement-by-two Arithmetic Structures • 19 “Decrement by two” means add − 2 • • Set the B input to 1102, then simplify We could use adder/subtractor in subtract mode and use B = 0102, but that requires more simplification!

Topics Arithmetic Structures • 20 Arithmetic Structures • • • Addition and Subtraction Contraction

Topics Arithmetic Structures • 20 Arithmetic Structures • • • Addition and Subtraction Contraction and Specialized Structures Other Arithmetic Operations

Zero-Fill and Sign Extension Arithmetic Structures • 21 • • Sometimes need to represent

Zero-Fill and Sign Extension Arithmetic Structures • 21 • • Sometimes need to represent an operand using additional bits • For example, add 4 -bit operand to an 8 -bit operand If unsigned, need to “zero-fill” • • • Append 0 s to most significant end of vector Example: 0101 becomes 00000101 Example: 1011 becomes 00001011 If signed, need to “sign extend” • • • Replicate MSb for additional upper bits Example: 0101 becomes 00000101 Example: 1011 becomes 11111011

Multiplication/Division Arithmetic Structures • • • General multipliers/dividers more complicated than we deal with

Multiplication/Division Arithmetic Structures • • • General multipliers/dividers more complicated than we deal with in this class Powers of 2 make multiply/divide easy: just shift left/right by log 2 of the multiplier/divisor… • • Example: 010102 × 410 = 01010002 Example: 011102 ÷ 210 = 001112 Can use a sequence of additions to multiply by a constant value… • Example: 011102 × 610 = (011102 × 410) + (011102 × 210) = 01110002 + 0111002 22 = 10101002

Arithmetic Structures ECE 352 Digital System Fundamentals Arithmetic Structures 23

Arithmetic Structures ECE 352 Digital System Fundamentals Arithmetic Structures 23