- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need a module to calculate the following:
d=((a xor b) xor c) Each variable is 32 bits in size. Also along with this I need signals like valid_in, valid_out and enable(en) for the module. Will the following constructs be useful for this module: wire [31:0] out1, out2; xor u1(out1,a,b); xor u2(out2,out1,c); assign d=out2; always @(out2) valid_out=1; I can't figure out how to include the enable signal in the module. Can anyone suggest how to do that?Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
always @(out2)
valid_out=1;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think, it would be easier to incorporate these signals if the design was sequential instead of combinational. It would also make it easier for me to calculate the latency of the module.
Converting the design to sequential, I'm using a 2 bit shift register 'tmp' to calculate the 'valid_out' signal which goes high on the next clock cycle after the 'valid_in' signal. What do you think about this code? module xorcomp( input clk, input [31:0] a, input [31:0] b, input [31:0] c, input valid_in, output valid_out ); reg [31:0] a_reg; reg [31:0] b_reg; reg [1:0] tmp; //the 2 bit shift register wire [31:0] a_wire; /*wires to copy the latched values of a, b, and c from registers a_reg, b_reg, c_reg*/ wire [31:0] b_wire; wire [31:0] c_wire; always @(posedge clk) begin if(valid_in=='1') begin a_reg<=a; b_reg<=b; c_reg<=c; tmp<=2'b01; end else tmp<=tmp<<1; end assign valid_out=tmp[1]; assign a_wire=a_reg; assign b_wire=b_reg; assign c_wire=c_reg; xor u1(out1,a_wire,b_wire); xor u2(out2,out1,c_wire); assign d=out2; endmodule
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page