difference if statement with case statement? 
Author Message
 difference if statement with case statement?

I want difference "if statement" with "case statement".
Give me the answer, please.

Sorry, I can't use English well, because English is foreign lenguage.



Sat, 23 Aug 2003 14:31:32 GMT  
 difference if statement with case statement?

Quote:
>I want difference "if statement" with "case statement".
>Give me the answer, please.

>Sorry, I can't use English well, because English is foreign lenguage.

An if statement only allows two possibilities.  "IF it's cold, I can wear a
jacket and be warm, or ELSE I can wear only a shirt and freeze."

A case statement allows more than two options.  "In CASE the temperature is
between 60F and 40F I will wear a light coat.  In CASE the temperature is
between 39F and 20F I will wear a medium coat.  In CASE the temperature is
19F or less, I will wear a heavy coat.  For other cases, I will stay
indoors and read comp.lang.vhdl."

I'm not sure what the differences would be in synthesis.

--
  :::::      Dave Ross / Dr. Watson          "Yesterday's technology

::    ===                                    tomorrow!"      
  :::::      http://www.enteract.com/~watson



Sat, 23 Aug 2003 14:50:17 GMT  
 difference if statement with case statement?

Quote:


> >I want difference "if statement" with "case statement".
> >Give me the answer, please.

> >Sorry, I can't use English well, because English is foreign lenguage.

> An if statement only allows two possibilities.  "IF it's cold, I can
> wear a jacket and be warm, or ELSE I can wear only a shirt and freeze."

> A case statement allows more than two options. "In CASE the temperature
> is between 60F and 40F I will wear a light coat. In CASE the temperature
> is between 39F and 20F I will wear a medium coat.  In CASE the
> temperature is 19F or less, I will wear a heavy coat.  For other cases,
> I will stay indoors and read comp.lang.vhdl."

> I'm not sure what the differences would be in synthesis.

Theory:
  The 'if' statement evaluates its condition every time it is
  executed (at simulation time), where the 'case' statement is a
  lookup table where all 'when' branches are pre-calculated
  (at compile time).
  -> That's one reason why the 'case' statement is so restrictive
     -> "locally static expressions" ~ expression that can be evaluated
        by the compiler without knowing the larger context

Practical:
  It's a question of taste. I would suggest the following:
  - if you want to implement a lockup table, use 'case-when'
  - otherwise use 'if-elsif...-else'

You can always convert a 'case-when' construct to an 'if-elsif-else' one,
but in general, you can't convert an 'if-elsif-else' to a 'case-when'
construct.

Andi

--

DS Diagonal Systems AG           http://www.diagonal.ch/
Tumigerstrasse 71                Tel:+41-1-905-6060
CH-8606 Greifensee/Switzerland   Fax:+41-1-905-6069



Sat, 23 Aug 2003 15:53:58 GMT  
 difference if statement with case statement?

Quote:
> I want difference "if statement" with "case statement".
> Give me the answer, please.

> Sorry, I can't use English well, because English is foreign lenguage.

The "if-statement" is used within state-machines (processes or procedures).
It is used for flow-control of sequential processes. In hardware terms this
means: Flip-Flops are invoked.
Synchronous or asynchronous machines are designed.

The "case-statement" describes a combinatiral logic (truth-tables,
look-up-tables). No Flip-Flops are invoked. Only combinatorial logic
functions like NAND, NOR etc. are implemented in the design.

Regards,
Norbert Zimmermann



Sat, 23 Aug 2003 17:21:25 GMT  
 difference if statement with case statement?
Norbert Zimmermann a crit :

Quote:

> > I want difference "if statement" with "case statement".
> > Give me the answer, please.

> > Sorry, I can't use English well, because English is foreign lenguage.

> The "if-statement" is used within state-machines (processes or procedures).
> It is used for flow-control of sequential processes. In hardware terms this
> means: Flip-Flops are invoked.

No:

process(A, B)
begin
  if(A = '1') then
    S <= '1';
  elsif(B = '1') then
    S <= '1';
  else
    S <= '0';
  end if;
end process;

is pure combinational, no DFF would be synthesized.

Quote:
> Synchronous or asynchronous machines are designed.

> The "case-statement" describes a combinatiral logic (truth-tables,
> look-up-tables). No Flip-Flops are invoked. Only combinatorial logic
> functions like NAND, NOR etc. are implemented in the design.

No:

process(CP)
  variable B: BOOLEAN;
begin
  B := RISING_EDGE(CP);
  case B is
    when TRUE => Q <= D;
    when FALSE => null;
  end case;
end process;

will synthesize as a DFF only, no combinational logic,
no NAND, NOR, etc.

Where does your assumption come from? Regards,
--
Renaud Pacalet, ENST / COMELEC, 46 rue Barrault 75634 Paris Cedex 13



Sat, 23 Aug 2003 22:42:55 GMT  
 difference if statement with case statement?

Quote:
> No:

> process(A, B)
> begin
>   if(A = '1') then
>     S <= '1';
>   elsif(B = '1') then
>     S <= '1';
>   else
>     S <= '0';
>   end if;
> end process;

> is pure combinational, no DFF would be synthesized.

> > Synchronous or asynchronous machines are designed.

> > The "case-statement" describes a combinatiral logic (truth-tables,
> > look-up-tables). No Flip-Flops are invoked. Only combinatorial logic
> > functions like NAND, NOR etc. are implemented in the design.

> No:

> process(CP)
>   variable B: BOOLEAN;
> begin
>   B := RISING_EDGE(CP);
>   case B is
>     when TRUE => Q <= D;
>     when FALSE => null;
>   end case;
> end process;

Sorry and thank you for correcting me... I mixed up the "case-statement"
with the "switch-statement" (which is combinatorial (please correct me, if I
am wrong)).. as for the "if-statement".. yeah, you seem to be right aswel..
:}   Learned something today...


Sat, 23 Aug 2003 23:07:17 GMT  
 difference if statement with case statement?
"if-elsif-else" implies priority while "case" does not. Consider

RTL 1:

if (Sel = "00") then
  A <= X"3f";
elsif (Sel = "01") then
  A <= X"5e";
elsif (Sel = "10") then
  A <= X"25";
else
  A <= X"66"
end if;

RTL 2:

case Sel is
      when "00" => A <= X"3f";
      when "01" => A <= X"5e";
      when "10" => A <= X"25";
      when others => A <= X"66";
 end case;

Both RTL 1 and RTL 2 function the same and are pure combination circuit,
but RTL 1 implies priority, "00" has higher priority than "01" and "11"
has the lowest priority. RTL 2 does not have priority. In synthesis, RTL
1 synthesized to a chain of comparison in serial while RTL 2 synthesized
to several multiplexers in parallel which is smaller and faster.
Therefore if your goal is hardware generation and you are trying to do
something like selector, use "case", but in some situations, using "if"
is simpler in coding and is more natural (even though the hardware
generated is not the one you want).

Quote:

> I want difference "if statement" with "case statement".
> Give me the answer, please.

> Sorry, I can't use English well, because English is foreign lenguage.



Sun, 24 Aug 2003 01:41:51 GMT  
 difference if statement with case statement?

Quote:

>   - if you want to implement a lockup table, use 'case-when'

---------------------------------^^^^^^

Oh horrors... :-)

SCNR,
  Colin



Sun, 24 Aug 2003 02:18:51 GMT  
 difference if statement with case statement?
bullshit /

well,

the real difference about if and case is here : the condition .
in an if statement u can have multiple conditions :
if (allo=1) then ...
elsif (robert=0) then
elsif (sel=00 AND allo=0) then
else ....
but case statement is handling only one object to handle the condition :
case sel is
when a sel is a
when b sel is b
when c don't care about allo but sel is c

but watch out theses two points :
- if the if command have several true conditions, allo=1 and robert=0 only
the first command will be executed as it is the first condition used (if
handle some kind of priority)
- always use an else statement with the if command / always use when others
with the case statement :
it alow the circuit to have a default behavior and avoid strange outputs at
init or at unhandled inputs.

dit moi t'es francais ?
where r u from to ask this trick question ? :)



Quote:
> I want difference "if statement" with "case statement".
> Give me the answer, please.

> Sorry, I can't use English well, because English is foreign lenguage.



Sun, 24 Aug 2003 17:58:00 GMT  
 difference if statement with case statement?
FPS France schrieb:

Quote:

> bullshit /

I think you misspelled "Hi" or "Hello" or any other nice greetings
(I too misspell words from time to time ;-)

--
Andi



Mon, 25 Aug 2003 03:15:24 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. case statement flipflop statement

2. difference between case and if statements

3. Switch statement with nested If statement

4. Unexpected STATEMENT FUNCTION statement

5. Difference between I-O and EXTEND clause in the OPEN statement

6. Differences between rules and if....then....statements

7. [Fwd: Case statements, decision trees, and good OO design]

8. SUNOS NAWK - TOLOWER - In a print statement convert string to lower case

9. CASE STATEMENT

10. Case statements in parallel

11. Detecting Multiple Events (was: Case Statements...)

12. Case Statements...

 

 
Powered by phpBB® Forum Software