Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arithmetic Logic Unit (ALU) Lecture L7.5 Section 7.5.

Similar presentations


Presentation on theme: "Arithmetic Logic Unit (ALU) Lecture L7.5 Section 7.5."— Presentation transcript:

1 Arithmetic Logic Unit (ALU) Lecture L7.5 Section 7.5

2 ALU

3 MODULE alu interface([A3..A0],[B3..B0], [s2..s0] -> [Y3..Y0],CF,OVF,ZF,NF); TITLE '4-bit ALU' DECLARATIONS " INPUT PINS " A3..A0 PIN; A = [A3..A0]; " 4-bit input A B3..B0 PIN; B = [B3..B0]; " 4-bit input B s2..s0 PIN; S = [s2..s0]; " 3-bit control input " OUTPUT PINS " Y3..Y0 PIN; Y = [Y3..Y0]; " 4-bit output Y CF, OVF, ZF, NF PIN ISTYPE 'com';

4 " INTERMEDIATE NODES " C4..C0 NODE ISTYPE 'com'; " internal carry vector Cin = [C3..C0]; " carry input vector Cout = [C4..C1]; " carry output vector E1 = !s2 & s1 & s0;" [E1,E2] = [0,1] for A - B E2 = !s2 & s1 & !s0;" [E1,E2] = [1,0] for B - A E = E1 # E2; Ain = A $ E1; " E1 = 1 for subtraction Bin = B $ E2; " E2 = 1 for subtraction not = !A; and = A & B; or = A # B; xorr = A $ B; SD = Ain $ Bin $ Cin; " sum/difference output

5 EQUATIONS C0 = E1 # E2; " E1 # E2 = 1 for subtraction Cout = Ain & Bin # (Ain $ Bin) & Cin; " carry/borrow output vector ZF = !Y3 & !Y2 & !Y1 & !Y0; " zero flag NF = Y3; " negative flag when (S == 0) then {Y = A; CF = 0; OVF = 0;}" A when (S == 1) then {Y = SD; CF = C4 $ E; OVF = C3 $ C4;}" A + B when (S == 2) then {Y = SD; CF = C4 $ E; OVF = C3 $ C4;}" A - B when (S == 3) then {Y = SD; CF = C4 $ E; OVF = C3 $ C4;}" B - A when (S == 4) then {Y = not; CF = 0; OVF = 0;}" NOT when (S == 5) then {Y = and; CF = 0; OVF = 0;}" AND when (S == 6) then {Y = or; CF = 0; OVF = 0;}" OR when (S == 7) then {Y = xorr; CF = 0; OVF = 0;}" XOR END alu


Download ppt "Arithmetic Logic Unit (ALU) Lecture L7.5 Section 7.5."

Similar presentations


Ads by Google