Advertisement
alexarcan

CA_LAB12/13

Dec 17th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module control_unit(
  2.   input clk, //synchronization signal
  3.   input reset_n, //asynchronous reset signal
  4.   input begin_sig, //synchronous input; replaces the BEGIN signal due to begin being a reserved Verilog word
  5.   output end_sig, //output; replaces signal END to avoid using the reserved Verilog word end
  6.   input count_7, //synchronous input; marks the completion of the 7 iterations
  7.   input q_0, //synchronous input; indicate the value of xi stored in Q[0]
  8.   output [6:0] c //outputs; the control signals for the multiplier device
  9. );
  10.  
  11.    reg [7:0] state,state_next;
  12.    always @ (*) begin
  13.     state_next = {state[6],state[5],state[4]& count_7, state[2] & ~q_0 |state[3] |  state[4] & ~count_7 & ~ q_0,state[2] & q_0 | state[4] &~ count_7 & q_0, state[1], begin_sig & state[0], state[0] & ~begin_sig | state[7] };
  14.  end
  15.  
  16.  assign {c,end_sig} = state;
  17.  always @ (posedge clk or negedge reset_n )
  18.     if (!reset_n) state<= 8'd1;
  19.     else state <= state_next;
  20.  endmodule  
  21.  
  22.  
  23.  
  24.  
  25. ==============================================================================================================
  26.  
  27. module counter(clk, count_up, clear, count_7);
  28.   input clk; //synchronization signal
  29.   input clear; //synchronous input; clears counter's content
  30.   input count_up; //synchronous input; increment counter's content
  31.   output count_7; //active when counter's content is 111
  32.  
  33. reg [2:0] state, state_next;
  34.  
  35.    always @(*) begin
  36.        state_next = 3'd0;
  37.        if (clear)
  38.          state_next = 3'd0;
  39.        else if (count_up)
  40.           state_next = {state[2]^(state[1] & state[0]), state[1]^state[0], ~state[0] };
  41.           else
  42.           state_next = state;
  43.           end
  44.   always@(posedge clk or posedge clear)
  45.       state <= state_next;
  46.  
  47.   assign count_7 = state[2] & state[1] & state[0]; // sau &state
  48.              
  49. endmodule
  50.  
  51.  
  52.  
  53. ==============================================================================================================
  54.  
  55. module sm_multiplier(
  56.   input clk, //synchronization signal
  57.   input reset, //asynchronous reset signal
  58.   input begin_sig, //synchronous input; external state signal triggering the start of the multiplication procedure
  59.   output end_sig, //output; marks the completion of multiplication procedure
  60.   input [7:0] inbus, //synchronous input; hold the operands to be read by the procedure
  61.   output [7:0] outbus //output: outbus data lines; written only when load_outbus is active (high) and kept in high impedance otherwise
  62. );
  63. counter cnt (
  64.    .clk(clk),
  65.    .reset(~clear),
  66.    .begin
  67.  
  68.  
  69.  
  70. ==============================================================================================================
  71.  
  72. module register_a(clk, clear, load_adder_result, adder_result, load_sign, sign, shift, shift_out, load_outbus, outbus, accumulator_value);
  73.   input clk; //synchronization signal
  74.   input clear; //synchronous input; clears register's content
  75.   input load_adder_result; //synchronous input; enables the loading of adder's result into the register
  76.   input [7:0] adder_result; //input: the adder's result on 8 bits having the cout concatenated as on the msb position
  77.   input load_sign; //synchronous input; enables the loading of the register's msb value
  78.   input sign; //input: the value of the msb to be loaded into register when load_sign is active (high)
  79.   input shift; //synchronous input; activates right-shifting of register's content with 1 position; the value shifted into is 0.
  80.   output shift_out; //alias for register's lsb (the value that is to be lost because of the right-shifting)
  81.   input load_outbus; //synchronous input; enables uploading the content of the register onto the outbus
  82.   output reg [7:0] outbus; //output: outbus data lines; written only when load_outbus is active (high) and kept in high impedance otherwise
  83.   output [6:0] accumulator_value; //output: the magnitude field of the register's stored number
  84.  
  85. reg [7:0] state, state_next;
  86.  
  87. always @(*) begin
  88.    state_next = 8'd0;
  89.    if (clear)
  90.       state_next = 8'd0;
  91.       else if (load_adder_result)
  92.          state_next = adder_result;
  93.    else if (load_sign)
  94.       state_next = {sign , state[6:0]};
  95.    else if (shift)
  96.       state_next = { 1'd0, state[7:1] };
  97.       else state_next = state;
  98. end
  99.  
  100. always @ (*) begin
  101.     if (load_outbus)
  102.        outbus = state;
  103.        else
  104.        outbus = 8'bz;
  105. end
  106.  
  107.  assign acumulator_value = outbus[6:0];
  108.  assign shift_out = state[0];
  109.    
  110.  always @(posedge clk)
  111.       state <= state_next;
  112. endmodule
  113.  
  114.  
  115.  
  116.  
  117. ==============================================================================================================
  118.  
  119.  
  120. module control_unit(
  121.   input clk, //synchronization signal
  122.   input reset_n, //asynchronous reset signal
  123.   input begin_sig, //synchronous input; replaces the BEGIN signal due to begin being a reserved Verilog word
  124.   output end_sig, //output; replaces signal END to avoid using the reserved Verilog word end
  125.   input count_7, //synchronous input; marks the completion of the 7 iterations
  126.   input q_0, //synchronous input; indicate the value of xi stored in Q[0]
  127.   output [6:0] c //outputs; the control signals for the multiplier device
  128. );
  129.  
  130.    reg [7:0] state,state_next;
  131.    always @ (*) begin
  132.     state_next = {state[6],state[5],state[4]& count_7, state[2] & ~q_0 |state[3] |  state[4] & ~count_7 & ~ q_0,state[2] & q_0 | state[4] &~ count_7 & q_0, state[1], begin_sig & state[0], state[0] & ~begin_sig | state[7] };
  133.  end
  134.  
  135.  assign {c,end_sig} = state;
  136.  always @ (posedge clk or negedge reset_n )
  137.     if (!reset_n) state<= 8'd1;
  138.     else state <= state_next;
  139.  endmodule  
  140.  
  141.  
  142. ==============================================================================================================
  143.  
  144.  
  145.   input clk;
  146.   input clear_bit_0;
  147.   input load_inbus;
  148.   input [7:0] inbus;
  149.   input load_outbus;
  150.   output reg [7:0] outbus;
  151.   input shift;
  152.   input shift_in;
  153.   output content_bit_0;
  154.  
  155. reg [7:0] state,state_next;
  156. always @(*) begin
  157.     state_next = 8'd0;
  158.     if (clear_bit_0) state_next = { state[7:1],1'b0};
  159.     if (load_inbus) state_next = inbus;
  160.     else state_next = state;
  161.     if (shift == 1)
  162.        state_next = {shift_in,state[7:1]};
  163.        else state_next = state;
  164. end
  165.  
  166. assign content_bit_0 = state[0];
  167. always @ (posedge clk) begin
  168.      state <= state_next;
  169. end
  170.  
  171.  always @ (*) begin
  172.     outbus = 8'bz;
  173.     if (load_outbus) outbus = state;
  174.     else outbus = 8'bz;
  175.   end
  176. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement