Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of a "plain" begin-end block?

I'm reading some third party Verilog, and found this:

function [31:0] factorial;
    input [3:0] operand;
    reg [3:0] index;

    begin
        factorial = operand ? 1 : 0;
        for(index = 2; index <= operand; index = index + 1)
        factorial = index * factorial;
    end
endfunction

It seems that the begin and end keywords are redundant here. Are they? What is their use?

like image 677
Randomblue Avatar asked Apr 02 '12 15:04

Randomblue


People also ask

What does begin END do in Verilog?

begin--end groups two or more statements together sequentially, so that statements are evaluated in the order they are listed. Each timing control is relative to the previous statement. fork--join groups two or more statements together in parallel, so that all statements are evaluated concurrently.

Is begin and end necessary in Verilog?

The initial block has only one statement and hence it is not necessary to place the statement within begin and end . This statement assigns the value 2'b10 to a when the initial block is started at time 0 units.

How many times the Begin End block will get executed?

In the above example, first statement in begin and end block will be executed at 10 time units, and the second statement at 30 time units because of the relative nature. It is 20 time units after execution of the previous statement.


1 Answers

I don't know about the general case, but in this specific case:

If a function contains more than one statement, the statements must be
enclosed in a begin-end or fork-join block. 

Source: Verilog Golden Reference Guide

like image 154
Tim Avatar answered Sep 20 '22 13:09

Tim