DIP-Switch Subtractor Example: Based Adding/Subtracting Calculator Color Space Converter – RGB to CMYK

DIP-Switch Subtractor Example: Based Adding/Subtracting Calculator Color Space Converter – RGB to CMYK

ECE 274 - Digital Logic 4.8 Lecture 12 Subtractor Can build subtractor as we built carry-ripple adder Mimic subtraction by hand Lecture 12 – Datapath Components Compute borrows from columns on left Use full-subtractor component: Subtractors wi is borrow by column on right, wo borrow from column on left Two’s Complement 1stcolumn 2ndcolumn 3rd column 4th column 0 0 1 10 0 1 0 Overflow 1100 1 11010 11010 1100 - 0111 - 0111 - 0111 - 0111 ALUs 1 1 1 0 1 1 0 0 1 1 Register Files a3 b3 a2 b2 a1 b1 a0 b0 wi abwi abwi abwi abwi a3 a2 a1 a0 b3 b2 b1 b0 FS FS FS FS 4-bit subtractor wi a wo s wo s wo s wo s wo s3s2s1s0 wo s3 s2 s1 s0 (b) (c) 1 2 Subtractor Example: DIP-Switch Subtractor Example: Based Adding/Subtracting Calculator Color Space Converter – RGB to CMYK Extend earlier DIP switches Color calculator example 1 Often represented as weights 0 of three colors: red, green, Switch f indicates and blue (RGB) whether want to 8 8 8 8 Perhaps 8 bits each, so add (f=0) or 00 specific color is 24 bits AABBci wi subtract (f=1) White: R=11111111, 8-bit adder 8-bit subtractor G=11111111, B=11111111 Use subtractor and coSS wo Black: R=00000000, 2x1 mux G=00000000, B=00000000 1 f 8 8 012x1 Other colors: values in 0 8 between, e.g., e R=00111111, G=00000000, • Printers use opposite color scheme ld 8-bit register B=00001111 would be a – Because inks absorb light clk reddish purple CALC – Use complementary colors of RGB: 8 Good for computer monitors, Cyan (absorbs red), reflects green which mix red, green, and and blue, Magenta (absorbs green), LEDs blue lights to form all colors and Yellow (absorbs blue) 3 4 Subtractor Example: Subtractor Example: Color Space Converter – RGB to CMYK Color Space Converter – RGB to CMYK RGB Printers must quickly 255 255 255 Try to save colored inks 8 8 8 convert RGB to CMY 8 8 8 Expensive C=255-R, M=255-G, Y=255-B Imperfect – mixing C, M, Y doesn’t o CMY t Use subtractors as shown --- yield good-looking black GB R Solution: Factor out the black or 888 gray from the color, print that CMY part using black ink e.g., CMY of (250,200,200)= (200,200,200) + (50,0,0). (200,200,200) is a dark gray – use black ink 5 6 Subtractor Example: Representing Negative Numbers: Color Space Converter – RGB to CMYK Two’s Complement Call black part K Negative numbers common RGBK 88 8 (200,200,200): K=200 Y How represent in binary? (Letter “B” already used for blue) o CM RGB t Signed-magnitude Compute minimum of C, RGB to CMY GB CM YR M, Y values Use leftmost bit for sign bit Use MIN component 8 8 8 8 So -5 would be: designed earlier, using C MY 1101 using four bits comparator and mux, to MIN 10000101 using eight bits compute K 8 Better way: Two’s complement Output resulting K value, and subtract K value MIN Big advantage: Allows us to perform subtraction using 8 from C, M, and Y values K addition Ex: Input of Thus, only need adder component, no need for separate (250,200,200) yields subtractor component! output of (50,0,0,200) --- 888 8 C2 M2 Y2 K 7 8 Ten’s Complement Ten’s Complement 1 9 Nice feature of ten’s complement 2 8 Instead of subtracting a number, adding its complement results in Before introducing two’s complement, let’s answer exactly 10 too much 3 7 consider ten’s complement So just drop the 1 – results in subtracting using addition only 4 6 complements But, be aware that computers DO NOT USE TEN’S 1 9 10 5 5 COMPLEMENT. Introduced for intuition only. 2 8 46 6 4 Complements for each base ten number shown to 3 7 7 7 3 right – Complement is the number that when 4 6 01020 added results in 10 8 2 5 5 Ð4 +6 3 - 13 9 1 6 4 13 7 3 3 8 2 7Ð4=3- 7+6=13 3 9 1 Adding the complement results in an answer exactly 10 too much – dropping the tens column gives 010theright answer. 9 10 Two’s Complement is Easy to Compute: Two’s Complement Subtractor Built Just Invert Bits and Add 1 with an Adder Hold on! Using two’s complement A B Sure, adding the ten’s complement achieves subtraction using addition A – B = A + (-B) only = A + (two’s complement of B) But don’t we have to perform subtraction to have determined the N-bit complement in the first place? e.g., we only know that the complement = A + invert_bits(B) + 1 of 4 is 6 by subtracting 10-4=6 in the first place. So build subtractor using A B 1 True – but in binary, it turns out that the two’s complement can be Adder cin computed easily adder by inverting B’s bits, Two’s complement of 011 is 101, because 011 + 101 is 1000 and setting carry in to 1 Could compute complement of 011 as 1000 – 011 = 101 S Easier method: Just invert all the bits, and add 1 The complement of 011 is 100+1 = 101 -- it works! Q: What is the two’s complement of 0101? A: 1010+1=1011 a (check: 0101+1011=10000) Q: What is the two’s complement of 0011? A: 1100+1=1101 11 12 Adder/Subtractor Example: Adder/Subtractor Calculator Previous calculator DIP switches Adder/subtractor: control used separate 1 input determines whether adder and 0 add or subtract subtractor 88 1 f AB Can use 2x1 mux – sub input sub 8-bit adder/subtractor Improve by using 0 passes either B or inverted B S adder/subtractor, 8 e Alternatively, can use XOR ld and two’s 8-bit register gates – if sub input is 0, B’s clk complement CALC bits pass through; if sub 8 DIP switches input is 1, XORs invert B’s numbers 1 0 LEDs bits 8 8 8 8 00 AABBci wi 8-bit adder 8-bit subtractor coSS wo 1 8 8 f 012x1 0 8 e ld 8-bit register clk CALC 8 LEDs 13 14 Design Challenge Not Really a Quiz Overflow Determine the two’s complement representation for the Sometimes result can’t be represented with given number following decimal numbers (assume we are using 5-bit of bits binary numbers): Either too large magnitude of positive or negative -1 e.g., 4-bit two’s complement addition of 0111+0001 (7+1=8). But -11 4-bit two’s complement can’t represent number >7 0111+0001 = 1000 WRONG answer, 1000 in two’s complement is - -15 8, not +8 Adder/subtractor should indicate when overflow has occurred, so Determine the two’s complement representation for same result can be discarded decimal numbers assuming we are using 6-bit binary numbers. 15 16 Detecting Overflow: Method 1 Detecting Overflow: Method 2 Assuming 4-bit two’s complement numbers, can detect overflow by Even simpler method: Detect difference between carry-in to sign bit detecting when the two numbers’ sign bits are the same but are and carry-out from sign bit different from the result’s sign bit Yields simpler circuit: overflow = c3 xor c4 If the two numbers’ sign bits are different, overflow is impossible Adding a positive and negative can’t exceed largest magnitude positive or negative Simple circuit 1 11 0 00 0 00 0111 1111 1000 overflow = a3’b3’s3 + a3b3s3’ Include “overflow” output bit on adder/subtractor +0001+0100+1011 sign bits 0111 1111 1000 001 000 1 0111 1111 overflow overflow no overflow +0001+0100+1011 (a) (b) (c) 1000 0111 1111 If the carry into the sign bit column differs from the carry out of that column, overflow has occurred. overflow overflow no overflow (a) (b) (c) If the numbers’ sign bits have the same value, which differs from the result’s sign bit, overflow has occurred. 17 18 4.9 Multifunction Calculator without an Arithmetic-Logic Unit: ALU ALU ALU: Component that Can build multifunction can perform any of calculator using separate various arithmetic components for each DIP switches (add, subtract, 1 operation, and muxes 0 increment, etc.) and 88 But too many wires, and logic (AND, OR, etc.) AB wasted power computing operations, based on Wasted all those operations when + Ð +1 AND OR XOR NOT power 8 control inputs 8 8 at any time you only use 8 8 8 8 Motivation: one of the results 8 A lot of wires 10 01234567 x Suppose want multi- s2 y 8-bit 8⋅ 1 function calculator that s1 z s0 not only adds and 8 e Id subtracts, but also 8-bit register clk increments, ANDs, ORs, CALC 8 XORs, etc. LEDs 19 20 Arithmetic-Logic Extender in Front ALU of ALU More efficient design uses ALU ALU design not just separate components multiplexed (same problem as previous slide!), Instead, ALU design uses single adder, plus logic in front of adder’s A and B inputs Logic in front is called an arithmetic-logic extender Extender modifies the A and B inputs such that desired operation will appear at output of the adder xyz=000: Want S=A+B – just pass a to ia, b to ib, and set cin=0 xyz=001: Want S=A-B – pass a to ia, b’ to ib, and set cin=1 xyz=010: Want S=A+1 – pass a to ia, set ib=0, and set cin=1 xyz=011: Want S=A – pass a to ia, set ib=0, and set cin=0 xyz=1000: Want S=A AND B – set ia=a*b, b=0, and cin=0 others: likewise Based on above, create logic for ia(x,y,z,a,b) and ib(x,y,z,a,b) for each abext, and create logic for cin(x,y,z), to complete design of the AL-extender component 21 22 ALU Example: Multifunction 4.10 Calculator Register Files DIP swi tches 1 MxN register file 0 88 er 32 AB component provides Wasted C + Ð +1 AND OR XOR NOT er C a power t 8 8 8 8 s 8 ompu t DIP switches efficient access to M N-? 8 8 8 8 d0 load o theab A lot of wi res.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us