4CS015 Lecture 4: Arithmetic Logic Units PDF

Summary

This is lecture 4 from course 4CS015, and introduces arithmetic logic units (ALUs). It covers what an ALU is, including its function unit, instruction decoder and output multiplexor. The lecture also covers turning an adder into a subtractor.

Full Transcript

4CS015 Lecture 4: Arithmetic Logic Units Prepared by: Uttam Acharya 1 Today What is an ALU? Function Unit Instruction Decoder Output Multiplexor Turning our adder into a subtractor...

4CS015 Lecture 4: Arithmetic Logic Units Prepared by: Uttam Acharya 1 Today What is an ALU? Function Unit Instruction Decoder Output Multiplexor Turning our adder into a subtractor 2 What is ALU? ALU Fig: Motherboard Fig: CPU 3 What is ALU? Performs set of arithmetic operations and set of logic operations Multi operation combinational logic circuit. It has a number of selection lines to select particular operation in the unit. 4 Arithmetic Logic Unit diagram Value 1 = 4 ALU Result = 9 Value 2 = 5 Operation = ADD 5 The ALU A function unit containing the logic blocks that simultaneously carry out each operation A controller that selects the required output according to the instruction The instruction is a binary ‘word’ A ‘switch’ that obeys the controller which connect the output to the required function 6 ALU Arithmetic and Logic Functions Output examples Output AND 1 bit ALU Logic AND 1 bit OR OR NOT NOT XOR XOR Ctrl Addition Addition Subtraction The controller “decodes” the instruction to select the Instr required output 7 ALU Decoder & Output Selection Controller takes an instruction Logic is used so that only one of the logic operation outputs reaches the result output. Output to ‘switch’ Binary Instruction Decoder Ctrl 8 ALU Instruction Decoder The decoder is a combinatorial logic circuit(CLC) The circuit in which, at any time output Instruction Output is only depends upon inputs only is Inst1 Inst2 ctrl1 ctrl2 ctrl3 ctrl4 called CLC 0 0 1 0 0 0 It converts binary information from 0 1 0 1 0 0 ‘n’ i/p lines to a maximum of 2n o/p lines 1 0 0 0 1 0 1 1 0 0 0 1 Multiple output lines, ctrl1 to clrl4 Only one of the output lines is ‘on’ for each instruction ‘n’ instruction lines = 2n control lines. Hence size of decoder is n* 2n 9 ALU Instruction Decoder (Contd.) From the truth table, we can design a logic circuit. Inst 1 ctrl Boolean expression for o/p is: Inst 2 1 ctrl1=Inst1’Inst2’, ctrl2=Inst1’Inst2, ctrl 2 ctrl3=Inst1Inst2’ and ctrl4=Inst1Inst2 ctrl 3 The arithmetic and logic function section ctrl performs all operations at the same time 4 So, we use the controller to select the output we want 10 ALU Output Multiplexor Lines from ALU logic Block If we have a collection of AND gates, connected to an OR gate, we have Output a logic circuit for the multiplexer Many to one Selects the outputs with the help of decoder outputs Control Lines lines output form Decoder from decoder 11 Half Adder (HA) Two bits adder circuit x s Number of inputs = 2 (x and y ‘say’) HA c y Number of outputs= 2 (sum and carry) For example: 0 0 1 1 Input Output +0 +1 +0 +1 x y Sum(s) Carry(c) 0 1 1 10 0 0 0 0 0 1 1 0 1 0 1 0 sum 1 1 0 1 carry 12 Half Adder (Contd…) Boolean expression for half adder Logic diagram output from truth table is as; (x⊕y) Sum(s)= x’y+xy’ x Sum y = (x⊕y) Carry(c)= xy xy Carry 13 Full Adder (FA) Block diagram Three bits adder circuit Number of input= 3(x,y and cin ) s x s x Number of output =2(sum and carry) HA-1 y HA-2 c c FA can be constructed using two y HA and OR gate cin c 14 Logic circuit diagram of FA x (x⊕y⊕ cin) x⊕y y (x⊕y) cin xy cin xy 15 ALU Components: Contd. Function Unit/ALU Logic Multiplexer(MUX) Operations Multiplexor A AND B OR XOR Output Full Adder Addition Circuit Carry in Carry out Inst1 ctrl1 Inst2 ctrl2 ctrl3 ctrl4 Decoder Decoder 16 Multi Bit ALU Carry out(C) Connect multiple single A2 R2 bit ALUs together B2 Carry out to carry The ‘carry out’ of each ALU A1 in links to ‘carry in’ of next ALU B1 R1 Final result is CR2R1R0 Carry out to carry in A0 R0 B0 Instruction s Carry in 17 Subtraction Subtraction can be done by adding A to the 2’s complement form of B. S = A+(2’s Complement of B) =A+(1’s complement of B+1) =A+(B’+1) The rule to convert B to –B in 2’s complement form is: Invert each bit (using NOT gates). Add 1. 18 Add / Subtract Circuit Both addition and subtraction circuits can be combined into a single circuit by using Controlled Inversion. A Control input determines whether the circuit adds or subtracts. 19 Controlled Inversion Consider the following truth table: Input Control will be the CONTROL. Input B is the Data. Input Control Input B Output F 0 0 0 Output F=B= 0 1 1 B 1 0 1 Output F=B’ 1 1 0 NOT B 20 Controlled Inversion (Contd.) When Control = 0 Then When Control = 1 Then This is the truth table for XOR Control Input B Output F 0 0 0 0 1 1 1 0 1 1 1 0 21 Circuit for Add / Subtract Unit Input Input B Output F 4-bit adder Control 0 0 0 Output F=B= B 0 1 1 1 0 1 Output F=B’ 0/1 1 1 0 NOT B 22 Control of the Add / Subtract Unit The Control determines the operation: Control = 0 : Addition Carry-in is 0. Output is A plus B plus 0. Control = 1 : Subtraction Carry-in is 1. Output is A plus ( inverse of B plus 1). which is A plus (-B). 23 Summary ALU Functions, controlling and multiplexing. Controlled inversion and subtraction. 24