Advertisement
Guest User

Question 2

a guest
Sep 12th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // -------------------------------------------------------------------------------------
  2. // Question 2
  3. // -------------------------------------------------------------------------------------
  4. module  Question_2 #(parameter width = 8)
  5. (
  6.     // Inputs
  7.     input       logic   [17:0]  SW,             // Switches
  8.     input   logic   [3:0]       KEY,                // Push Buttons
  9.     input       logic               CLOCK_27,       // Clock
  10.     input       logic               CLOCK_50,       // Clock
  11.    
  12.     // Outputs
  13.     output  logic   [6:0]       HEX0,               // SSD 0
  14.                                     HEX1,               // SSD 1
  15.                                     HEX2,               // SSD 2
  16.                                     HEX3,               // SSD 3
  17.                                     HEX4,               // SSD 4
  18.                                     HEX5,               // SSD 5
  19.                                     HEX6,               // SSD 6
  20.                                     HEX7,               // SSD 7
  21.     output  logic   [17:0]  LEDR,               // Red LEDS
  22.     output  logic   [8:0]       LEDG                // Green LEDS
  23.    
  24. );
  25.  
  26.     // Internal Logic
  27.     logic [width-1:0]   A,
  28.                         B,
  29.                         B_sign_out,
  30.                         C,
  31.                         AU_XNOR_out,
  32.                         AU_XOR_out,
  33.                         LO_AND_out,
  34.                         LO_OR_out,
  35.                         LO_XOR_out,
  36.                         LO_NOR_out,
  37.                         AU_out,
  38.                         LO_out,
  39.                         LO_1,
  40.                         LO_2,
  41.                         LO_3,
  42.                         ALU_out;
  43.     logic   [3:0]       F;
  44.     logic               Cout,
  45.                         OVs,
  46.                         OVu,
  47.                         OV;
  48.    
  49.     // Assigning Numbers A and B to the Inputs Switches
  50.     assign A = SW[15:8];
  51.     assign B = SW[7:0];
  52.     assign F = KEY[3:0];
  53.    
  54.     // Displaying the Inputs
  55.     disp_8b_SSD disp_A(A[width-1:0], HEX6[6:0], HEX7[6:0]);
  56.     disp_8b_SSD disp_B(B[width-1:0], HEX4[6:0], HEX5[6:0]);
  57.    
  58.     // ---- Add/Subtract Hardware with Overflow Detection ----
  59.    
  60.     // AU - Choose between Add and Sub Mode
  61.     parameterized_2_1_MUX #(width) mux1(B[width-1:0], ~(B[width-1:0]), F[1], B_sign_out[width-1:0]);
  62.    
  63.     // AU - Adding A and (-)B
  64.     adder_12_bit(A[width-1:0], mux_1_out[width-1:0], F[1], C[width-1:0], Cout);
  65.    
  66.     // AU - Top XNOR
  67.     assign AU_XNOR_out[width-1:0] = B_sign_out[width-1:0] ~^ A[width-1:0];
  68.    
  69.     // AU - Top XOR
  70.     assign AU_XOR_out[width-1:0] = A[width-1:0] ^ C[width-1:0];
  71.    
  72.     // AU - OVs
  73.     assign OVs = AU_XNOR_out[width-1:0] & AU_XOR_out[width-1:0];                    // NEED TO CHECK WHETHER OVs IS N-BIT OR 1 BIT
  74.    
  75.     // AU - OVu
  76.     assign OVu = Cout ^ F[1];
  77.    
  78.     // AU - Overall Overflow OV
  79.     parameterized_2_1_MUX #(width) mux2(OVs, OVu, F[0], OV);
  80.    
  81.     // Turning on LED is OV is detected
  82.     assign LEDR[0] = OV;
  83.    
  84.     // ---- SLT Logic ----
  85.    
  86.     // AU - LO_1
  87.     parameterized_2_1_MUX #(width) mux3(C[width-1:0], Cout, OVs, LO_1);
  88.    
  89.     // AU - LO_2
  90.     parameterized_2_1_MUX #(width) mux4(LO_1[width-1:0], ~Cout, F[0], LO_2[width-1:0]);
  91.    
  92.     // AU - LO_3 - Zero Extension
  93.     // TODO
  94.    
  95.     // AU - LO_3
  96.     parameterized_2_1_MUX #(width) mux5(LO_3[width-1:0], C[width-1:0], ~F[2], AU_out[width-1:0]);
  97.    
  98.     // LO - AND
  99.     assign LO_AND_out[width-1:0] = A[width-1:0] & B[width-1:0];
  100.    
  101.     // LO - OR
  102.     assign LO_OR_out[width-1:0] = A[width-1:0] | B[width-1:0];
  103.    
  104.     // LO - XOR
  105.     assign LO_XOR_out[width-1:0] = A[width-1:0] ^ B[width-1:0];
  106.    
  107.     // LO - NOR
  108.     assign LO_NOR_out[width-1:0] = A[width-1:0] ~| B[width-1:0];
  109.    
  110.     // LO - LO_out
  111.     parameterized_4_1_MUX #(width) mux6(LO_AND_out[width-1:0], LO_OR_out[width-1:0], LO_XOR_out[width-1:0], LO_NOR_out[width-1:0], F[1:0], LO_out[width-1:0]);
  112.    
  113.     // ALU_out
  114.     parameterized_2_1_MUX #(width) mux7(ALU_out[width-1:0], LO_out[width-1:0], F[2], ALU_out[width-1:0]);
  115.    
  116.     // ---- Displaying the Result ----
  117.    
  118.     disp_equals_sign(HEX3[6:0]);
  119.     display_8b_with_Cout disp_ALU_out(ALU_out[width-1:0], Cout, HEX0[6:0], HEX1[6:0], HEX2[6:0]);
  120.    
  121. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement