Eight Bit Divider: Quotient and Remainder

隐身守侯 提交于 2019-12-13 02:48:37

问题


I am trying to debug my code shown below. I am fairly new to SystemVerilog and hopefully I can learn from this. Let me know of any suggestions.

The errors I am receiving are:

Error-[ICPD] Invalid procedural driver combination
"divide.v", 2
Variable "Q" is driven by an invalid combination of procedural drivers. 
Variables written on left-hand of "always_comb" cannot be written to by any 
other processes, including other "always_comb" processes.
"divide.v", 2: logic [7:0] Q;
"divide.v", 8: always_comb  begin
if (x <= R) begin
...
"divide.v", 5: Q = 8'b0;

Error-[ICPD] Invalid procedural driver combination 
"divide.v", 2
Variable "R" is driven by an invalid combination of procedural drivers. 
Variables written on left-hand of "always_comb" cannot be written to by any 
other processes, including other "always_comb" processes.
"divide.v", 2: logic [7:0] R;
"divide.v", 8: always_comb  begin
if (x <= R) begin
...
"divide.v",6: R = y;

My SystemVerilog Code is:

module divider(input  logic [7:0] x,y,
               output logic [7:0] Q,R);
  initial
    begin
      Q = 8'd0;
      R = y;
    end
  always_comb
    begin
      if (x<=R)
        begin R <= R - x; Q <= Q + 8'd1; end
    end
endmodule

module test1; 

  logic [7:0] x,y,Q,R;

  divider Divider1 (x,y,Q,R);

  initial 
    begin
      x = 8'd2;
      y = 8'd8;
    end
endmodule

回答1:


Generally, in Verilog/SystemVerilog you cannot assign to a variable from two parallel blocks (with some exceptions). You are assigning to R and Q from two places: the initial block and the always_comb block.

Although the initial block only runs once, it runs in parallel with the always_comb block at the beginning of the simulation, which is a violation of this rule.

Why don't you get rid of the initial block and do everything in always_comb?

   always_comb
    begin
      Q = 8'd0;     // set initial value of Q
      R = y;        // set initial value of R
      ....          //THE REST OF THE ALGORITHM
    end

Also, you are missing using a loop!




回答2:


An important distinction between writing System Verilog (or any HDL) and writing in any software language (C/C++, Java, etc) is that System Verilog is designed to facilitate describing hardware structures while allowing for software-like testbenches, while software languages are designed to allow users to give instructions to an interpreter, VM or actual hardware. That being said, you need to think first about the hardware you are trying to describe and then write the associated HDL code. There are numerous posts describing the differences between HDLs and software languages (ex: Can Verilog/Systemverilog/VHDL be considered actor oriented programming languages?).

Looking at your code and flow chart you were given, it appears you are trying to use System Verilog as a programming language rather than a HDL. For example, initial blocks are generally only used in test benches and not in modules themselves. Also, as your algorithm is sequential, it is likely you will need a clock signal and registers, but the way your code lacks both.

Ideally, you should have a good idea of how to design digital hardware systems before trying to code any HDL, as this is the mentality you should have using HDLs. The goal is generally to translate a hardware design into HDL, so understanding digital design will help clarify alot.



来源:https://stackoverflow.com/questions/25952406/eight-bit-divider-quotient-and-remainder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!