1
module circuit_1 (a, b, c);
input [1:0J a,b;
output [3:0J c;
assign c = a + b;

If input a = 2'b11 and input b = 2'b10,

what value would output c have ? Please give a descriptive answer.

Also kindly tell me functionality of assign and always. I am a bit confused.

2
  • This is more of a Binary Mathematics question. Please read the wikipedia page then update the question with your proposed answer. Commented Mar 25, 2013 at 8:12
  • RE assign and always, the Q&A Format here does not lend itself well to additional questions. You can ask a new question but the answer will likely be check out the LRM - Language Reference Manual - SystemVerilog 2012 Particularly section 10, Assignment statements starting on page 196. Commented Mar 25, 2013 at 9:07

2 Answers 2

7
c = 4'b0101      // Output, implicitly a wire

"assign" is used for net type declarations(Wire,Tri etc).Since wires change values according to the value driving them, whenever the operands on the RHS changes,the value is evaluated and assigned to LHS(simulating a wire)

always - is used for registers + combinational logic. If it is always(@ posedge clk)- The event posedge clk triggers the always block and the logic inside the block is evaluated and assigned.

always @ (*) - If something in the RHS of the always block changes,that particular expression is evaluated and assigned.

Imagine assign as wires and always blocks as registers (For now) , as their behavior is same.

Sign up to request clarification or add additional context in comments.

5 Comments

always @* is for reg types not registers, assign implies the same combinatorial logic as always @*. always @(posedge clk) implies flip-flops (registers).
My bad.. I knew it but failed to explain it
No problem, you can edit you answers to improve it if you wish.
@Morgan If assign implies the same combinational logic as always @* why do I have to use reg-variables for the always-block and wires for the assign? Why can't I use the wires for the always-block too?
@GURKE because that is not valid syntax. reg was intended to mean flip flop, but the combinatorial usage messed that up. Modern versions of verilog (ie SystemVerilog) you can use logic instead, for all uses except multi driven wires. I think this is a pretty good answer: stackoverflow.com/a/33462996/97073 An external reference: blogs.mentor.com/verificationhorizons/blog/2013/05/03/…
0

c = 0101, actually c[2:0] become 101 but extension of 0 takes place as c is a 4 bit data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.