EmbDev.net

Forum: FPGA, VHDL & Verilog verilog if else to casex


von Coder (Guest)


Rate this post
useful
not useful
Replace this if-then statement with a casex statement

reg A, B, C, D, E, F, G, H;
always@(*)
if (A) H = F & G;
else if (B) H = F | G;
else if (C) H = F ^ G;
else H = D & E;

von user (Guest)


Rate this post
useful
not useful
We do not do your homework! Show what you have and ask questions, so we 
can help.

von Coder (Guest)


Attached files:

Rate this post
useful
not useful
Please see the attached file.
That is what i think , i dont know the correct use of casex statement 
and the parameters to be given inside casex()
please help me out

von Johann Klammer (Guest)


Rate this post
useful
not useful
1
reg A, B, C, D, E, F, G, H;
2
always@(*)
3
casex({A,B,C})
4
  3'b1xx:H = F & G;
5
  3'b01x:H = F | G;
6
  3'b001:H = F ^ G;
7
  3'b000:H = D & E;

think in sets.
The first if only concerns the A, the others don't matter.
the second if is inside the else clause to the first if so A==0 and 
B==1. c
does not matter. the third if is in the else clause to the previous 
statements, so A==0 B==0 and C==1. the last else selects the only 
leftover condition. A==0 B==0 C==0.

    A  B  C
    0  0  0  ->what's left for the else
    0  0  1  ->third if
    0  1  0  \->second if
    0  1  1  /
    1  0  0  \
    1  0  1   |
    1  1  0   |->first if
    1  1  1  /

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.