EmbDev.net

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


Author: Coder (Guest)
Posted on:

Rate this post
0 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;

Author: user (Guest)
Posted on:

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

Author: Coder (Guest)
Posted on:
Attached files:

Rate this post
0 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

Author: Johann Klammer (Guest)
Posted on:

Rate this post
0 useful
not useful
reg A, B, C, D, E, F, G, H;
always@(*)
casex({A,B,C})
  3'b1xx:H = F & G;
  3'b01x:H = F | G;
  3'b001:H = F ^ G;
  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  /

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig