1 / 6

TOPIC : Multi-way branching

TOPIC : Multi-way branching. MODULE : Behavioral modeling. UNIT : Modeling in Verilog. Conditional statements : Case statement. Conditional Statements, there were many alternatives, from which one was chosen.

hye
Télécharger la présentation

TOPIC : Multi-way branching

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TOPIC : Multi-way branching MODULE : Behavioral modeling UNIT : Modeling in Verilog

  2. Conditional statements : Case statement • Conditional Statements, there were many alternatives, from which one was chosen. • The nested if-else-if can become unwieldy if there are too many alternatives. • A shortcut to achieve the same result is to use the case statement. • This compares 0,1,x and z of the condition, bit by bit with the different case options. • If width of condition and a case option are unequal, they are zero filled to match the bid width of the widest of both.

  3. Syntax of case statement case ( expression) alternative1: statement1; alternative2: statement2; alternative3: statement3; ... default: default-statement; endcase NOTE: If none of the alternatives match, the default-statement is executed. The default-statement is optional.

  4. CASE statements example //Execute statements based on the ALU control signal reg [1:01 alu-control; ... case (alu-control) 2'd0 : y = x + z; 2'd1 : y = x - z; 2'd2 : y = x * z; default: $display("Inva1id ALU control signal"); endcase

  5. The casex and casez statements • Casez does not compare z-values in the condition and case options. All bit positions with z may be represented as ? in that position. • Casex does not compare both x and z-values in the condition and case options

  6. Example of casex casex(encoding) 4’b1xxx: next_state = 3; 4’bx1xx: next_state = 2; 4’bxx1x: next_state = 1; 4’bxxx1: next_state = 0; Endcase //encoding = 4’b10xz will cause next_state=3

More Related