Question.1
If a is 0 and b is 1 right before the clock edge, what are their values immediately after the clock edge?
always @(posedge clk) begin
a <= b;
b <= a;
end
Blocking (=): Executes immediately, sequential.
a = b; c = a; // c gets new a
Non-blocking (<=): Updates scheduled, parallel.
a <= b; c <= a; // c gets old a
= in combinational always blocks.<= in sequential (clocked) always blocks.+, -, *, /, %
signed.x.reg signed [3:0] x = -3, y = 2;
assign z = x / y; // result = -1
+, -<, <=, >, >=
1 or 0.x/z → result = x.==, != → logical compare, x/z → x.===, !== → case equality (checks x/z too).if (a === 1'bx) $display("a is unknown");
&&, ||, !
x/z as unknown (x).&, |, ^, ~^
assign y = a ^ b; // XOR
<<, >> → logical shift.<<<, >>> → arithmetic shift (preserve sign).reg signed [7:0] a = -4;
assign b = a >>> 1; // arithmetic shift right → -2
assign x = {a, b}; // concat
assign y = {4{1’b1}}; // replicate → 1111
Applies operator across all bits: &a, |a, ^a, ~&a, etc.
assign parity = ^data; // XOR reduction (parity bit)
?:)assign out = sel ? a : b;
?:) operator is an inline if–else in an expression: y = sel ? a : b;sel=1 → use the then value; sel=0 → use the else value.sel = x/z: Verilog evaluates both branches and merges bit-by-bit:x.(1’bx) ? 4’b1111 : 4’b1111 → 1111(1’bx) ? 4’b1111 : 4’b0000 → xxxx$signed(expression)expression into a signed expression of the same bit-width.Example:
reg [3:0] a = 4'b1000; // 8 (unsigned)
$display("%0d", $signed(a)); // -8
$unsigned(expression)expression into an unsigned expression of the same bit-width.Example:
reg signed [3:0] b = 4'b1000; // -8 (signed)
$display("%0d", $unsigned(b)); // 8