Sequential Statements - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Sequential Statements

Description:

For example, if a variable r is a record with two fields a and b, then they ... when orange to turquoise = statements for these colours; end case; case opcode of ... – PowerPoint PPT presentation

Number of Views:172
Avg rating:3.0/5.0
Slides: 14
Provided by: FSK6
Category:

less

Transcript and Presenter's Notes

Title: Sequential Statements


1
Sequential Statements
  • Variable Assignment
  • For example, if a variable r is a record with two
    fields a and b, then they could be exchanged by
    writing
  • (a gt r.b, b gt r.a) r
  • If Statement
  • if_statement if condition then sequence_of_st
    atements elsif condition then sequence_of_state
    ments else sequence_of_statements end if

2
If Statement (con)
  • Example 1
  • if en1 then stored_value data_in
  • end if
  • Example 2
  • if sel0 then result lt input_0 -- executed
    if sel 0
  • else
  • result lt input_1 -- executed if sel / 0
  • end if

3
If Statement (con)
  • Example 3
  • if opcode halt_opcode then PC
    effective_address -- all three statements are
  • executing false -- are executed one after
  • halt_indicator true -- another
  • end if
  • Example 4 (nested)
  • if phase wash then
  • if cycle_select delicate_cycle then
  • agitator_speed lt slow
  • else agitator_speed lt slow
  • end if
  • agitator_on lt true
  • end if

4
If Statement (con)
  • There are also attributes of signals (S). The
    most common type use with if statement is
  • Sevent True if there is an event on S in the
    current simulation cycle, false otherwise
  • Example 5
  • if (clkevent and clk1) then -- active when
    rising edge
  • .
  • end if
  • if (clkevent and clk0) then -- active when
    falling edge
  • .
  • end if

5
Case Statement
  • Case Statement
  • Some examples of case statements
  • case element_colour of when red gt statements
    for red when green blue gt statements for
    green or blue when orange to turquoise
    gt statements for these coloursend case
  • case opcode of when X"00" gt perform_add when
    X"01" gt perform_subtract when others gt
    signal_illegal_opcodeend case

6
Case Statement (con)
  • Example
  • type opcodes is
  • (nop, add, subtract, load, store, jump,
    jumpsub, branch, halt)
  • case opcode is
  • when load add subtract gt
  • operand memory_operand
  • when store jump jumpsub branch gt
  • operand address_operand
  • when others gt -- for last alternatives
  • operand 0
  • end case

7
Case Statement (con)
  • The previous case statement could be rewritten as
  • case opcode is
  • when add to load gt
  • operand memory_operand
  • when branch downto store gt
  • operand address_operand
  • when others gt
  • operand 0
  • end case

8
Case Statement (con)
  • Another way is to use range constraint
  • subtype control_transfer_opcodes is opcodes
    range jump to branch
  • case opcode is
  • when control_transfer_opcodes store gt
  • operand address_operand

9
Case Statement (con)
  • Case statement must all be written using locally
    static value
  • Illegal example
  • variable N integer 1
  • case expression is
  • when N N1gt -- illegal since N might
    change during
  • when N2 to N5 gt -- the course of
    execution, these choices
  • when others gt -- are not locally static
  • end case
  • Legal example
  • constant C integer 1
  • case expression is
  • when C C1gt
  • when C2 to C5 gt
  • when others gt
  • end case

10
Loop Statement
  • Loop Statements
  • An example of such a basic loop is
  • loop do_somethingend loop
  • An example of using while loop statment
  • while index lt length and str(index) / ' '
    loop index index 1end loop
  • An example of using For Loop statment
  • for item in 1 to last_item loop table(item)
    0end loop

11
Loop Statements Con..
  • for i in 1 to max_str_len loop a(i)
    buf(i) exit when buf(i) NULend loop
  • outer_loop loop inner_loop
    loop do_something next outer_loop when temp
    0 do_something_else end loop
    inner_loopend loop outer_loop

12
Sequential Statements
  • Null Statement
  • The null statement has no effect. It may be used
    to explicitly show that no action is required in
    certain cases. example
  • case controller_command is when forward gt
    engage_motor_forward when reverse gt
    engage_motor_reverse when idle gt nullend
    case

13
Sequential Statements
  • Assertions.
  • An assertion statement is used to verify a
    specified condition and to report if the
    condition is violated.
  • The syntax is
  • assertion_statement assert condition
    report expression severity expression
Write a Comment
User Comments (0)
About PowerShow.com