data/full_repos/permissive/122497324/assignment_4/assignment_4.v
 line:593: before: "("
1: b'%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:238: Cell has missing pin: \'store_mux_stall\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b010)) FP_add_station\n                                                    ^~~~~~~~~~~~~~\n                     ... Use "/* verilator lint_off PINMISSING */" and lint_on around source to disable this message.\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:238: Cell has missing pin: \'trigger_exes\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b010)) FP_add_station\n                                                    ^~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:238: Cell has missing pin: \'memory_offset_out\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b010)) FP_add_station\n                                                    ^~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:238: Cell has missing pin: \'valid_data\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b010)) FP_add_station\n                                                    ^~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:254: Cell has missing pin: \'store_mux_stall\'\n  reservation_station #(.BUS_LENGTH(1),.ID(3\'b001)) FP_mult_station\n                                                    ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:254: Cell has missing pin: \'trigger_exes\'\n  reservation_station #(.BUS_LENGTH(1),.ID(3\'b001)) FP_mult_station\n                                                    ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:254: Cell has missing pin: \'memory_offset_out\'\n  reservation_station #(.BUS_LENGTH(1),.ID(3\'b001)) FP_mult_station\n                                                    ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:254: Cell has missing pin: \'valid_data\'\n  reservation_station #(.BUS_LENGTH(1),.ID(3\'b001)) FP_mult_station\n                                                    ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:270: Cell has missing pin: \'trigger_exes\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b011)) store_station\n                                                    ^~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:286: Cell has missing pin: \'store_mux_stall\'\n  reservation_station #(.BUS_LENGTH(2),.ID(3\'b100)) load_station\n                                                    ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:315: Cell has missing pin: \'bbus_data_in\'\n  execution_unit #(.CYCLE_TIME(2),.ID(2\'b11)) load_store_unit\n                                              ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:315: Cell has missing pin: \'fake_clock\'\n  execution_unit #(.CYCLE_TIME(2),.ID(2\'b11)) load_store_unit\n                                              ^~~~~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'offset_in\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'memory_in\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'store_dbus_data_in\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'fake_clock\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'memory_address\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'memory_out\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:329: Cell has missing pin: \'op_code_out\'\n  execution_unit #(.CYCLE_TIME(3),.ID(2\'b10)) FP_add_unit\n                                              ^~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'offset_in\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'memory_in\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'store_dbus_data_in\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'memory_address\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'memory_out\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-PINMISSING: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:341: Cell has missing pin: \'op_code_out\'\n  execution_unit #(.CYCLE_TIME(5),.ID(2\'b01)) FP_mult_unit\n                                              ^~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:962: Operator ASSIGN expects 32 bits on the Assign RHS, but Assign RHS\'s CONST \'31\'bzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\' generates 31 bits.\n                                                                                    : ... In instance assignment_4.load_store_unit\n    memory_address = 31\'bz;\n                   ^\n%Warning-WIDTH: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:1007: Operator ADD expects 32 bits on the RHS, but RHS\'s VARREF \'offset_in\' generates 3 bits.\n                                                                                     : ... In instance assignment_4.load_store_unit\n              memory_address = abus_data_in + offset_in;\n                                            ^\n%Warning-WIDTH: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:1014: Operator ADD expects 32 bits on the RHS, but RHS\'s VARREF \'offset_in\' generates 3 bits.\n                                                                                     : ... In instance assignment_4.load_store_unit\n              memory_address = abus_data_in + offset_in;\n                                            ^\n%Warning-WIDTH: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:583: Operator ASSIGN expects 3 bits on the Assign RHS, but Assign RHS\'s CONST \'8\'bzzzzzzzz\' generates 8 bits.\n                                                                                    : ... In instance assignment_4.FP_add_station\n    d_select_out = 8\'bz;\n                 ^\n%Warning-UNSIGNED: data/full_repos/permissive/122497324/assignment_4/assignment_4.v:463: Comparison is constant due to unsigned arithmetic\n                                                                                       : ... In instance assignment_4\n    if((memory_address >= 0) && (load_store > 3\'b000)) begin\n                       ^~\n%Error: Exiting due to 30 warning(s)\n'
module reservation_station #(parameter BUS_LENGTH = 1, ID=3'b000)
  (

    clk, fake_clock, fake_mux_clock, station_selected, opbus_op, opbus_dest, opbus_src_a, opbus_src_b, abus_in, bbus_in, busy_bus,
    execution_unit_busy, cdbus_dest, cdbus_dest_shift, cdbus_dest_data, cdbus_valid, store_mux_stall,

    a_select_out, b_select_out, d_select_out, d_select_out_shift, abus_out, bbus_out, op_code_out, station_full, trigger_exes,
    memory_offset_out, valid_data
  );

  input clk;



  input fake_clock;

  input fake_mux_clock;

  input station_selected;

  input [2:0] opbus_op;
  input [2:0] opbus_dest;
  input [2:0] opbus_src_a;
  input [2:0] opbus_src_b;

  input [31:0] abus_in,bbus_in;

  input [7:0] busy_bus;

  input execution_unit_busy;

  input [2:0] cdbus_dest;
  input [7:0] cdbus_dest_shift;
  input [31:0] cdbus_dest_data;
  input cdbus_valid;
  input store_mux_stall;

  output reg [7:0] a_select_out;
  output reg [7:0] b_select_out;

  output reg [7:0] d_select_out_shift;
  output reg [2:0] d_select_out;

  output reg [31:0] abus_out, bbus_out;

  output reg [2:0] op_code_out;

  output reg station_full;


  output reg trigger_exes;

  output reg [2:0] memory_offset_out;
  output reg valid_data;




  reg[2:0] op_code [BUS_LENGTH:0];
  reg[2:0] dest_reg [BUS_LENGTH:0];
  reg[7:0] dest_reg_shift [BUS_LENGTH:0];
  reg[2:0] src_a [BUS_LENGTH:0];
  reg[7:0] src_a_shift [BUS_LENGTH:0];
  reg[2:0] src_b [BUS_LENGTH:0];
  reg[7:0] src_b_shift [BUS_LENGTH:0];

  reg[31:0] abus_data[BUS_LENGTH:0];
  reg[31:0] bbus_data[BUS_LENGTH:0];


  reg[BUS_LENGTH:0] operation_data_a_ready;
  reg[BUS_LENGTH:0] operation_data_b_ready;

  reg[BUS_LENGTH:0] station_in_use;
  reg[BUS_LENGTH:0] a_b_equal;


  reg[31:0] counter;
  reg[31:0] counter2;
  reg[31:0] counter3;
  

  reg[31:0] a_update_index;
  reg[31:0] b_update_index;
  reg a_update_index_flag;
  reg b_update_index_flag;
  reg output_bus_touched;
  
  initial begin
    trigger_exes = 0;
    a_update_index = 0;
    b_update_index = 0;
    a_update_index_flag = 0;
    b_update_index_flag = 0;

    a_select_out = 8'bz;
    b_select_out = 8'bz;
    d_select_out = 8'bz;
    d_select_out_shift = 8'bz;
    abus_out = 32'bz;
    bbus_out = 32'bz;
    op_code_out = 3'bz;
    station_full = 0;
    counter = 0;
    output_bus_touched = 0;
    memory_offset_out = 3'bz;
    valid_data = 0;
    repeat(BUS_LENGTH+1) begin
      op_code[counter] = 3'b0;
      dest_reg[counter] = 3'b0;
      dest_reg_shift[counter] = 8'b0;
      src_a[counter] = 3'b0;
      src_a_shift[counter] = 8'b0;
      src_b[counter] = 3'b0;
      src_b_shift[counter] = 8'b0;
      abus_data[counter] = 32'b0;
      bbus_data[counter] = 32'b0;
      operation_data_a_ready[counter] = 0;
      operation_data_b_ready[counter] = 0;
      station_in_use[counter] = 0;
      a_b_equal[counter] = 0;
      counter = counter+1;
    end
    counter = 0;
    counter2 = 0;
    counter3 = 0;
  end
  



  always @(fake_clock) begin

    counter = 0;
    counter2 = 0;
    counter3 = 0;
    a_update_index_flag = 0;
    b_update_index_flag = 0;

    if(!station_full) begin


      if(station_selected) begin:enqueue_op_break
        repeat(BUS_LENGTH+1) begin:enqueue_op_continue
          if(!station_in_use[counter]) begin
            $display("RS ID=%d, station %d is not in use, filling", ID, counter);

            op_code[counter] [2:0] = opbus_op;
            dest_reg_shift[counter] [7:0] = 8'b00000001 << opbus_dest;
            dest_reg[counter] [2:0] = opbus_dest;
            src_a[counter] [2:0] = opbus_src_a;
            src_b[counter] [2:0] = opbus_src_b;
            src_a_shift[counter] [7:0] = 8'b00000001 << opbus_src_a;
            src_b_shift[counter] [7:0] = 8'b00000001 << opbus_src_b;
            a_b_equal[counter] = 0;
            operation_data_a_ready[counter] = 0;
            operation_data_b_ready[counter] = 0;
            station_in_use[counter] = 1;

            if(counter == BUS_LENGTH) begin
              station_full = 1;
              $display("RS ID=%d, reservation station is full", ID);
            end

            disable enqueue_op_break;
          end
          counter = counter+1;
        end
      end
    end
  end
  

  always @(fake_mux_clock) begin
    counter = 0;

    begin:data_check_break
      repeat(BUS_LENGTH+1) begin:data_check_continue
        if(station_in_use[counter]) begin
          $display("RS ID=%d, station %d is in use", ID, counter);


          if(!operation_data_a_ready[counter]) begin
            $display("RS ID=%d, data for a (regsiter %d) of station %d is not ready", ID, src_a[counter], counter);


            if(dest_reg[counter] == src_a[counter])begin
              $display("RS ID=%d, dest_reg and src_a match (%d) for station %d, ignoring",ID, src_a[counter],counter);
              operation_data_a_ready[counter]=1;
            end
            else if(cdbus_dest == src_a[counter]) begin
              $display("RS ID=%d, cdbus says data is relavent (destination register %d) for source a at station %d ", ID, cdbus_dest, counter);

              abus_data[counter] = cdbus_dest_data;
              operation_data_a_ready[counter]=1;





              if(counter > 0) begin: WAW_check_break_a
                counter3 = counter-1;
                repeat(counter) begin
                  if(dest_reg[counter3] == src_a[counter])begin
                    $display("RS ID=%d, setting ready flag for source a of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                    operation_data_a_ready[counter]=0;
                  end
                  counter3 = counter3-1;
                end
              end
            end
            else if(!busy_bus[src_a[counter]]) begin
              $display("RS ID=%d, busybus says register %d for a is up to date for station %d", ID, src_a[counter], counter);


              a_select_out = src_a_shift[counter];
              a_update_index = counter;

              operation_data_a_ready[counter]=1;
              a_update_index_flag = 1;
            end
          end

          case(op_code[counter])
            3'b001: begin

              operation_data_b_ready[counter]=1;
            end
            3'b010: begin

              if(!operation_data_b_ready[counter]) begin
                $display("RS ID=%d, store data for d (regsiter %d) of station %d is not ready", ID, dest_reg[counter], counter);

                if(cdbus_dest == dest_reg[counter]) begin
                  $display("RS ID=%d, cdbus says data is relavent (destination register %d) for load source d at station %d ", ID, dest_reg[counter], counter);
                  bbus_data[counter] = cdbus_dest_data;
                  operation_data_b_ready[counter]=1;
                  if(counter > 0) begin: WAW_check_break_b_store
                    counter3 = counter-1;
                    repeat(counter) begin
                      if(dest_reg[counter3] == dest_reg[counter])begin
                        $display("RS ID=%d, setting ready flag for source b of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                        operation_data_b_ready[counter]=0;
                      end
                      counter3 = counter3-1;
                    end
                  end
                end
                else if(!busy_bus[dest_reg[counter]]) begin
                  $display("RS ID=%d, busybus says register %d for b is up to date for station %d", ID, dest_reg[counter], counter);


                  b_select_out = dest_reg_shift[counter];
                  b_update_index = counter;

                  operation_data_b_ready[counter]=1;
                  b_update_index_flag = 1;
                end
              end
            end
            default: begin
              if(src_a[counter] == src_b[counter]) begin
                $display("RS ID=%d, src_a and b match(%d), setting match bit and copying data, station %d", ID, src_b[counter], counter);
                a_b_equal[counter] = 1;
                operation_data_b_ready[counter] = 1;
                b_update_index_flag = 1;
                b_update_index = counter;
              end
              else if(!operation_data_b_ready[counter]) begin
                $display("RS ID=%d, data for b (regsiter %d) of station %d is not ready", ID, src_b[counter], counter);

                if(dest_reg[counter] == src_b[counter])begin
                  $display("RS ID=%d, dest_reg and src_b match (%d) for station %d, ignoring",ID, src_b[counter],counter);
                  operation_data_b_ready[counter]=1;
                end
                if(cdbus_dest == src_b[counter]) begin
                  $display("RS ID=%d, cdbus says data is relavent (destination register %d) for source b at station %d ", ID, src_b[counter], counter);
                  bbus_data[counter] = cdbus_dest_data;
                  operation_data_b_ready[counter]=1;
                  if(counter > 0) begin: WAW_check_break_b
                    counter3 = counter-1;
                    repeat(counter) begin
                      if(dest_reg[counter3] == src_b[counter])begin
                        $display("RS ID=%d, setting ready flag for source b of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                        operation_data_b_ready[counter]=0;
                      end
                      counter3 = counter3-1;
                    end
                  end
                end
                else if(!busy_bus[src_b[counter]]) begin
                  $display("RS ID=%d, busybus says register %d for b is up to date for station %d", ID, src_b[counter], counter);


                  b_select_out = src_b_shift[counter];
                  b_update_index = counter;

                  operation_data_b_ready[counter]=1;
                  b_update_index_flag = 1;
                end
              end
            end
          endcase
        end
        counter = counter+1;
      end
    end
  end
  

  always @(negedge clk) begin
    counter = 0;
    output_bus_touched = 0;
    valid_data = 0;

    if(a_update_index_flag) begin
      abus_data[a_update_index] = abus_in;
    end
    if(b_update_index_flag) begin
      if(a_b_equal[counter]) begin
      bbus_data[b_update_index] = abus_in;
      end
      else begin
      bbus_data[b_update_index] = bbus_in;
      end
    end
    a_update_index_flag = 0;
    b_update_index_flag = 0;
    begin:data_output_break

      repeat(BUS_LENGTH+1) begin:data_output_continue
        if(station_in_use[counter] && operation_data_a_ready[counter] && operation_data_b_ready[counter] && !execution_unit_busy) begin
          if((ID==3'b010) && (store_mux_stall))begin
            $display("RS ID=%d, stalled due to waiting on mux", ID);
            valid_data = 1;
            disable data_output_break;
          end

          $display("RS ID=%d, station %d is in use, and operation data is ready, dequeuing for execution", ID,counter);
          output_bus_touched = 1;
          valid_data = 1;
          abus_out = abus_data[counter];
          bbus_out = bbus_data[counter];
          d_select_out = dest_reg[counter];
          d_select_out_shift = dest_reg_shift[counter];
          op_code_out = op_code[counter];
          memory_offset_out = src_b[counter];


          counter2 = counter;
          repeat(BUS_LENGTH - counter)begin
            op_code[counter2] = op_code[counter2+1];
            dest_reg[counter2] = dest_reg[counter2+1];
            dest_reg_shift[counter2] = dest_reg_shift[counter2+1];
            src_a[counter2] = src_a[counter2+1];
            src_a_shift[counter2] = src_a_shift[counter2+1];
            src_b[counter2] = src_b[counter2+1];
            src_b_shift[counter2] = src_b_shift[counter2+1];
            abus_data[counter2] = abus_data[counter2+1];
            bbus_data[counter2] = bbus_data[counter2+1];
            operation_data_a_ready[counter2] = operation_data_a_ready[counter2+1];
            operation_data_b_ready[counter2] = operation_data_b_ready[counter2+1];
            station_in_use[counter2] = station_in_use[counter2+1];
            a_b_equal[counter2] = a_b_equal[counter2+1];
            counter2 = counter2+1;
          end

          op_code[BUS_LENGTH] = 0;
          dest_reg[BUS_LENGTH] = 0;
          dest_reg_shift[BUS_LENGTH] = 0;
          src_a[BUS_LENGTH] = 0;
          src_a_shift[BUS_LENGTH] = 0;
          src_b[BUS_LENGTH] = 0;
          src_b_shift[BUS_LENGTH] = 0;
          abus_data[BUS_LENGTH] = 0;
          bbus_data[BUS_LENGTH] = 0;
          operation_data_a_ready[BUS_LENGTH] = 0;
          operation_data_b_ready[BUS_LENGTH] = 0;
          station_in_use[BUS_LENGTH] = 0;
          a_b_equal[BUS_LENGTH] = 0;

          if(station_full) begin
            $display("RS ID=%d, reservation station is no longer full", ID);
          end
          station_full = 0;
          disable data_output_break;
        end
        counter = counter+1;
      end

      if(!output_bus_touched) begin
        if((ID==3'b011)||(ID==3'b100)) begin
          $display("RS ID=%d, no instructions ready for execution unit, setting valid data to false", ID);
          valid_data =0;
        end
        else begin
          $display("RS ID=%d, no instructions ready for execution unit, closing outputs", ID);
          abus_out = 32'bz;
          bbus_out = 32'bz;
          d_select_out = 3'bz;
          d_select_out_shift = 8'bz;
          op_code_out = 3'bz;
        end
      end
    end
    trigger_exes = ~trigger_exes;
  end
endmodule
module reservation_station #(parameter BUS_LENGTH = 1, ID=3'b000)
  (

    clk, fake_clock, fake_mux_clock, station_selected, opbus_op, opbus_dest, opbus_src_a, opbus_src_b, abus_in, bbus_in, busy_bus,
    execution_unit_busy, cdbus_dest, cdbus_dest_shift, cdbus_dest_data, cdbus_valid, store_mux_stall,

    a_select_out, b_select_out, d_select_out, d_select_out_shift, abus_out, bbus_out, op_code_out, station_full, trigger_exes,
    memory_offset_out, valid_data
  );


  input clk;



  input fake_clock;

  input fake_mux_clock;

  input station_selected;

  input [2:0] opbus_op;
  input [2:0] opbus_dest;
  input [2:0] opbus_src_a;
  input [2:0] opbus_src_b;

  input [31:0] abus_in,bbus_in;

  input [7:0] busy_bus;

  input execution_unit_busy;

  input [2:0] cdbus_dest;
  input [7:0] cdbus_dest_shift;
  input [31:0] cdbus_dest_data;
  input cdbus_valid;
  input store_mux_stall;

  output reg [7:0] a_select_out;
  output reg [7:0] b_select_out;

  output reg [7:0] d_select_out_shift;
  output reg [2:0] d_select_out;

  output reg [31:0] abus_out, bbus_out;

  output reg [2:0] op_code_out;

  output reg station_full;


  output reg trigger_exes;

  output reg [2:0] memory_offset_out;
  output reg valid_data;




  reg[2:0] op_code [BUS_LENGTH:0];
  reg[2:0] dest_reg [BUS_LENGTH:0];
  reg[7:0] dest_reg_shift [BUS_LENGTH:0];
  reg[2:0] src_a [BUS_LENGTH:0];
  reg[7:0] src_a_shift [BUS_LENGTH:0];
  reg[2:0] src_b [BUS_LENGTH:0];
  reg[7:0] src_b_shift [BUS_LENGTH:0];

  reg[31:0] abus_data[BUS_LENGTH:0];
  reg[31:0] bbus_data[BUS_LENGTH:0];


  reg[BUS_LENGTH:0] operation_data_a_ready;
  reg[BUS_LENGTH:0] operation_data_b_ready;

  reg[BUS_LENGTH:0] station_in_use;
  reg[BUS_LENGTH:0] a_b_equal;


  reg[31:0] counter;
  reg[31:0] counter2;
  reg[31:0] counter3;
  

  reg[31:0] a_update_index;
  reg[31:0] b_update_index;
  reg a_update_index_flag;
  reg b_update_index_flag;
  reg output_bus_touched;
  
  initial begin
    trigger_exes = 0;
    a_update_index = 0;
    b_update_index = 0;
    a_update_index_flag = 0;
    b_update_index_flag = 0;

    a_select_out = 8'bz;
    b_select_out = 8'bz;
    d_select_out = 8'bz;
    d_select_out_shift = 8'bz;
    abus_out = 32'bz;
    bbus_out = 32'bz;
    op_code_out = 3'bz;
    station_full = 0;
    counter = 0;
    output_bus_touched = 0;
    memory_offset_out = 3'bz;
    valid_data = 0;
    repeat(BUS_LENGTH+1) begin
      op_code[counter] = 3'b0;
      dest_reg[counter] = 3'b0;
      dest_reg_shift[counter] = 8'b0;
      src_a[counter] = 3'b0;
      src_a_shift[counter] = 8'b0;
      src_b[counter] = 3'b0;
      src_b_shift[counter] = 8'b0;
      abus_data[counter] = 32'b0;
      bbus_data[counter] = 32'b0;
      operation_data_a_ready[counter] = 0;
      operation_data_b_ready[counter] = 0;
      station_in_use[counter] = 0;
      a_b_equal[counter] = 0;
      counter = counter+1;
    end
    counter = 0;
    counter2 = 0;
    counter3 = 0;
  end
  



  always @(fake_clock) begin

    counter = 0;
    counter2 = 0;
    counter3 = 0;
    a_update_index_flag = 0;
    b_update_index_flag = 0;

    if(!station_full) begin


      if(station_selected) begin:enqueue_op_break
        repeat(BUS_LENGTH+1) begin:enqueue_op_continue
          if(!station_in_use[counter]) begin
            $display("RS ID=%d, station %d is not in use, filling", ID, counter);

            op_code[counter] [2:0] = opbus_op;
            dest_reg_shift[counter] [7:0] = 8'b00000001 << opbus_dest;
            dest_reg[counter] [2:0] = opbus_dest;
            src_a[counter] [2:0] = opbus_src_a;
            src_b[counter] [2:0] = opbus_src_b;
            src_a_shift[counter] [7:0] = 8'b00000001 << opbus_src_a;
            src_b_shift[counter] [7:0] = 8'b00000001 << opbus_src_b;
            a_b_equal[counter] = 0;
            operation_data_a_ready[counter] = 0;
            operation_data_b_ready[counter] = 0;
            station_in_use[counter] = 1;

            if(counter == BUS_LENGTH) begin
              station_full = 1;
              $display("RS ID=%d, reservation station is full", ID);
            end

            disable enqueue_op_break;
          end
          counter = counter+1;
        end
      end
    end
  end
  

  always @(fake_mux_clock) begin
    counter = 0;

    begin:data_check_break
      repeat(BUS_LENGTH+1) begin:data_check_continue
        if(station_in_use[counter]) begin
          $display("RS ID=%d, station %d is in use", ID, counter);


          if(!operation_data_a_ready[counter]) begin
            $display("RS ID=%d, data for a (regsiter %d) of station %d is not ready", ID, src_a[counter], counter);


            if(dest_reg[counter] == src_a[counter])begin
              $display("RS ID=%d, dest_reg and src_a match (%d) for station %d, ignoring",ID, src_a[counter],counter);
              operation_data_a_ready[counter]=1;
            end
            else if(cdbus_dest == src_a[counter]) begin
              $display("RS ID=%d, cdbus says data is relavent (destination register %d) for source a at station %d ", ID, cdbus_dest, counter);

              abus_data[counter] = cdbus_dest_data;
              operation_data_a_ready[counter]=1;





              if(counter > 0) begin: WAW_check_break_a
                counter3 = counter-1;
                repeat(counter) begin
                  if(dest_reg[counter3] == src_a[counter])begin
                    $display("RS ID=%d, setting ready flag for source a of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                    operation_data_a_ready[counter]=0;
                  end
                  counter3 = counter3-1;
                end
              end
            end
            else if(!busy_bus[src_a[counter]]) begin
              $display("RS ID=%d, busybus says register %d for a is up to date for station %d", ID, src_a[counter], counter);


              a_select_out = src_a_shift[counter];
              a_update_index = counter;

              operation_data_a_ready[counter]=1;
              a_update_index_flag = 1;
            end
          end

          case(op_code[counter])
            3'b001: begin

              operation_data_b_ready[counter]=1;
            end
            3'b010: begin

              if(!operation_data_b_ready[counter]) begin
                $display("RS ID=%d, store data for d (regsiter %d) of station %d is not ready", ID, dest_reg[counter], counter);

                if(cdbus_dest == dest_reg[counter]) begin
                  $display("RS ID=%d, cdbus says data is relavent (destination register %d) for load source d at station %d ", ID, dest_reg[counter], counter);
                  bbus_data[counter] = cdbus_dest_data;
                  operation_data_b_ready[counter]=1;
                  if(counter > 0) begin: WAW_check_break_b_store
                    counter3 = counter-1;
                    repeat(counter) begin
                      if(dest_reg[counter3] == dest_reg[counter])begin
                        $display("RS ID=%d, setting ready flag for source b of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                        operation_data_b_ready[counter]=0;
                      end
                      counter3 = counter3-1;
                    end
                  end
                end
                else if(!busy_bus[dest_reg[counter]]) begin
                  $display("RS ID=%d, busybus says register %d for b is up to date for station %d", ID, dest_reg[counter], counter);


                  b_select_out = dest_reg_shift[counter];
                  b_update_index = counter;

                  operation_data_b_ready[counter]=1;
                  b_update_index_flag = 1;
                end
              end
            end
            default: begin
              if(src_a[counter] == src_b[counter]) begin
                $display("RS ID=%d, src_a and b match(%d), setting match bit and copying data, station %d", ID, src_b[counter], counter);
                a_b_equal[counter] = 1;
                operation_data_b_ready[counter] = 1;
                b_update_index_flag = 1;
                b_update_index = counter;
              end
              else if(!operation_data_b_ready[counter]) begin
                $display("RS ID=%d, data for b (regsiter %d) of station %d is not ready", ID, src_b[counter], counter);

                if(dest_reg[counter] == src_b[counter])begin
                  $display("RS ID=%d, dest_reg and src_b match (%d) for station %d, ignoring",ID, src_b[counter],counter);
                  operation_data_b_ready[counter]=1;
                end
                if(cdbus_dest == src_b[counter]) begin
                  $display("RS ID=%d, cdbus says data is relavent (destination register %d) for source b at station %d ", ID, src_b[counter], counter);
                  bbus_data[counter] = cdbus_dest_data;
                  operation_data_b_ready[counter]=1;
                  if(counter > 0) begin: WAW_check_break_b
                    counter3 = counter-1;
                    repeat(counter) begin
                      if(dest_reg[counter3] == src_b[counter])begin
                        $display("RS ID=%d, setting ready flag for source b of station %d back to false because hazard conflicts with destination of station %d", ID,counter,counter3);
                        operation_data_b_ready[counter]=0;
                      end
                      counter3 = counter3-1;
                    end
                  end
                end
                else if(!busy_bus[src_b[counter]]) begin
                  $display("RS ID=%d, busybus says register %d for b is up to date for station %d", ID, src_b[counter], counter);


                  b_select_out = src_b_shift[counter];
                  b_update_index = counter;

                  operation_data_b_ready[counter]=1;
                  b_update_index_flag = 1;
                end
              end
            end
          endcase
        end
        counter = counter+1;
      end
    end
  end
  

  always @(negedge clk) begin
    counter = 0;
    output_bus_touched = 0;
    valid_data = 0;

    if(a_update_index_flag) begin
      abus_data[a_update_index] = abus_in;
    end
    if(b_update_index_flag) begin
      if(a_b_equal[counter]) begin
      bbus_data[b_update_index] = abus_in;
      end
      else begin
      bbus_data[b_update_index] = bbus_in;
      end
    end
    a_update_index_flag = 0;
    b_update_index_flag = 0;
    begin:data_output_break

      repeat(BUS_LENGTH+1) begin:data_output_continue
        if(station_in_use[counter] && operation_data_a_ready[counter] && operation_data_b_ready[counter] && !execution_unit_busy) begin
          if((ID==3'b010) && (store_mux_stall))begin
            $display("RS ID=%d, stalled due to waiting on mux", ID);
            valid_data = 1;
            disable data_output_break;
          end

          $display("RS ID=%d, station %d is in use, and operation data is ready, dequeuing for execution", ID,counter);
          output_bus_touched = 1;
          valid_data = 1;
          abus_out = abus_data[counter];
          bbus_out = bbus_data[counter];
          d_select_out = dest_reg[counter];
          d_select_out_shift = dest_reg_shift[counter];
          op_code_out = op_code[counter];
          memory_offset_out = src_b[counter];


          counter2 = counter;
          repeat(BUS_LENGTH - counter)begin
            op_code[counter2] = op_code[counter2+1];
            dest_reg[counter2] = dest_reg[counter2+1];
            dest_reg_shift[counter2] = dest_reg_shift[counter2+1];
            src_a[counter2] = src_a[counter2+1];
            src_a_shift[counter2] = src_a_shift[counter2+1];
            src_b[counter2] = src_b[counter2+1];
            src_b_shift[counter2] = src_b_shift[counter2+1];
            abus_data[counter2] = abus_data[counter2+1];
            bbus_data[counter2] = bbus_data[counter2+1];
            operation_data_a_ready[counter2] = operation_data_a_ready[counter2+1];
            operation_data_b_ready[counter2] = operation_data_b_ready[counter2+1];
            station_in_use[counter2] = station_in_use[counter2+1];
            a_b_equal[counter2] = a_b_equal[counter2+1];
            counter2 = counter2+1;
          end

          op_code[BUS_LENGTH] = 0;
          dest_reg[BUS_LENGTH] = 0;
          dest_reg_shift[BUS_LENGTH] = 0;
          src_a[BUS_LENGTH] = 0;
          src_a_shift[BUS_LENGTH] = 0;
          src_b[BUS_LENGTH] = 0;
          src_b_shift[BUS_LENGTH] = 0;
          abus_data[BUS_LENGTH] = 0;
          bbus_data[BUS_LENGTH] = 0;
          operation_data_a_ready[BUS_LENGTH] = 0;
          operation_data_b_ready[BUS_LENGTH] = 0;
          station_in_use[BUS_LENGTH] = 0;
          a_b_equal[BUS_LENGTH] = 0;

          if(station_full) begin
            $display("RS ID=%d, reservation station is no longer full", ID);
          end
          station_full = 0;
          disable data_output_break;
        end
        counter = counter+1;
      end

      if(!output_bus_touched) begin
        if((ID==3'b011)||(ID==3'b100)) begin
          $display("RS ID=%d, no instructions ready for execution unit, setting valid data to false", ID);
          valid_data =0;
        end
        else begin
          $display("RS ID=%d, no instructions ready for execution unit, closing outputs", ID);
          abus_out = 32'bz;
          bbus_out = 32'bz;
          d_select_out = 3'bz;
          d_select_out_shift = 8'bz;
          op_code_out = 3'bz;
        end
      end
    end
    trigger_exes = ~trigger_exes;
  end
endmodule