用verilog HDL语法编写

用for语句实现8位奇偶校验器。a为输入信号,它是位宽为8位的矢量。当a中有奇数个1,奇偶校验输出为1;否则为0。(提示奇数个1异或结果为1)。(以截图的形式(程序和波形图放在一个画面中),a输入的数据分别是00000000  01001010  01101010  11010101 10110100 11111111)

img


`timescale 1ns/1ns

module testbench_odd_check;

reg    [7:0]    a;
wire        c;

initial begin
    a = 'b0 ;
    forever #10  a = a + 1'b1 ;
end

    odd_check    ux
    (
        .a        (a),
        .c        (c)
    );

endmodule

module odd_check
(
    input    [7:0]    a,
    output    reg        c
);
    integer    i;
    
    always@(*)
    begin
        c    = 0;
        for(i=0;i<8;i=i+1)
        begin
            if(a[i])
                c    = c^1;
        end
    end

endmodule