Unit Ii Asic PDF
Unit Ii Asic PDF
Unit Ii Asic PDF
1. List system verilog introduces new data types with the following benefits.
2. "bit" and "logic" data types: These are new data types that allow for efficient
modeling of single-bit signals and multi-bit buses. They provide better
modeling capabilities than using simple integer types.
3. "enum" data type: This data type allows you to define a set of named values,
which makes it easier to create and maintain complex state machines. It also
provides better readability of code.
4. "struct" and "union" data types: These data types allow you to group related
variables together, which makes your code easier to read and understand. They
also provide a more flexible way to define data structures.
5. "packed" and "unpacked" arrays: These data types provide a way to define arrays
of different dimensions and types. Packed arrays are used for efficient
modeling of multi-bit buses, while unpacked arrays are used for more complex
data structures.
6. "interface" data type: This data type allows you to define a set of signals and
operations that can be used to communicate between different modules or
blocks. This makes it easier to create reusable and modular code.
Overall, these new data types provided by SystemVerilog allow for more efficient and
flexible modeling, improved code readability, and easier verification.
9. List system verilog introduces new data types with the following benefits.
SystemVerilog introduces a new data type, the queue, which provides easy
searching and sorting in a structure that is as fast as a fixed-size array but as
versatile as a linked list.
Like a dynamic array, queues can grow and shrink, but with a queue you
can easily add and remove elements anywhere. Example 2-17 adds and
removes values from a queue.
Example 2-17 Queue operations
int j = 1,
b[$] = {3,4},
q[$] = {0,2,5}; // {0,2,5} Initial queue
initial begin
q.insert(1, j); // {0,1,2,5} Insert 1 before 2
q.insert(3, b); // {0,1,2,3,4,5} Insert whole q.
q.delete(1); // {0,2,3,4,5} Delete elem. #1
// The rest of these are fast
q.push_front(6); // {6,0,2,3,4,5} Insert at front
j = q.pop_back; // {6,0,2,3,4} j = 5
q.push_back(8); // {6,0,2,3,4,8} Insert at back
j = q.pop_front; // {0,2,3,4,8} j = 6
foreach (q[i])
$display(q[i]);
end
When you create a queue, SystemVerilog actually allocates extra space so
you can quickly add extra elements. Note that you do not need to call the
new[] operator for a queue. If you add enough elements so that the queue
runs out of space, SystemVerilog automatically allocates additional space. As
a result, you can grow and shrink a queue without the performance penalty of
a dynamic array.
It is very efficient to push and pop elements from the front and back of a
queue, taking a fixed amount of time no matter how large the queue. Adding
10. Using break statement in systemverilog, write a program for the following output:
Iteration [0] to Iteration [5].
11. Differentiate between functions and task in systemverilog with a suitable example.
In SystemVerilog, a task and a function are both procedural blocks that allow you to
group a set of statements together and give them a name. However, there are some
key differences between tasks and functions:
1. Return Type: A task does not return any value while a function must have a
return type.
2. Arguments: Both tasks and functions can take arguments, but tasks can have
output and inout arguments, while functions can only have input arguments.
3. Blocking vs Non-Blocking: A task executes in a blocking manner, meaning that
it will complete all of its statements before control returns to the calling
process. On the other hand, a function can be either blocking or non-blocking,
depending on whether it uses the "automatic" keyword or not.
4. Control Flow: Tasks are generally used for controlling the overall flow of a
simulation, such as initializing variables or starting and stopping processes.
Functions are used for calculations or operations that need to return a value.
In summary, tasks and functions both provide a way to group a set of statements
together, but they differ in their return types, arguments, blocking vs non-blocking
execution, and usage.
You can create new types using the typedef statement. For example, you
may have an ALU that can be configured at compile-time to use on 8, 16, 24,
or 32-bit operands. In Verilog you would define a macro for the operand
width and another for the type.
Example 2-24 User-defined type-macro in Verilog
// Old Verilog style
`define OPSIZE 8
`define OPREG reg [`OPSIZE-1:0]
`OPREG op_a, op_b;
You are not really creating a new type; you are just performing text substitution.
In SystemVerilog you create a new type with the following code. This
book uses the convention that user-defined types use the suffix “_t.”
Example 2-25 User-defined type in SystemVerilog
// New SystemVerilog style
parameter OPSIZE = 8;
typedef reg [OPSIZE-1:0] opreg_t;
opreg_t op_a, op_b;
15. Discuss the nonblocking assignment of system Verilog and write a system Verilog code
to perform sum of two variables using nonblocking statements.
Nonblocking assignments are used in System Verilog to model the behavior of
synchronous digital circuits. They are used to model sequential logic in the form of
flip-flops, registers, and other sequential elements. Nonblocking assignments are
executed after all blocking assignments in a given time step and are scheduled for the
next time step.
a <= b + c;
In this example, a is assigned the value of b + c nonblockingly. This means that
the value of a will not be updated until the next time step. Nonblocking
assignments are used to model sequential logic, where the output of a flip-flop
or register is only updated on the positive edge of the clock.
module non_blocking_example(input logic [7:0] a, b, output logic
[8:0] sum);
endmodule
In this example, the input variables a and b are added together using the + operator and
the result is assigned to the output variable sum. The always block is triggered on the
positive edge of the clock (posedge clk), and the nonblocking delay #1 is used to
delay the update of sum until the next time step.
It's important to note that nonblocking assignments should be used when modeling
sequential logic, while blocking assignments should be used for combinational logic.
Using blocking assignments to model sequential logic can lead to race conditions and
other unexpected behavior.
17. Describe the purpose of Break and continue statements with an example.
In SystemVerilog, the break and continue statements can be used while reading a file
to alter the flow of execution within loops.
When reading a file, we typically use a while or for loop to read each line of the file until
the end of the file is reached. Within these loops, we can use break and continue
statements to control the flow of execution under certain conditions.
The break statement can be used to immediately terminate the loop and exit the loop's
block of code when a certain condition is met. For example, if we are reading a file line
by line and we want to stop reading the file once we encounter a certain string, we can
use the break statement to terminate the loop as soon as that string is found.
On the other hand, the continue statement can be used to skip over certain lines
of the file under certain conditions. For example, if we want to skip over lines that
start with a certain character or string, we can use the continue statement to skip
over those lines and continue reading the rest of the file.
Two new statements help with loops. First, if you are in a loop, but want to
skip over rest of the statements and do the next iteration, use continue. If
you want to leave the loop immediately, use break.
The following loop reads commands from a file using the amazing file I/O
code that is part of Verilog-2001. If the command is just a blank line, the code
just does a continue and skips any further processing of the command. If the
command is “done,” the code does a break to terminate the loop.
18. Describe the purpose of break and continue while reading a file in systemverilog.
19. Write a short note on task and functions in system verilog with the help of an example
Verilog makes a very clear differentiation between tasks and functions.
The most important difference is that a task can consume time while a
function cannot. A function cannot have a delay, #100, a blocking statement
such as @(posedge clock) or wait(ready), or call a task. Additionally, a
Verilog function must return a value, and the value must be used, as in an
assignment statement.
In SystemVerilog, if you want to call a function and ignore its return
value, cast the result to void. This might be done if you are calling the
function to use a side effect.
If you have a SystemVerilog task that does not consume time,
you should make it a void function that is a function that
does not return a value. Now it can be called from any task or
function. For maximum flexibility, any debug routine should
be a void function rather than a task so that it can be called
from any task or function.
variable = expression;
module procedural_example;
// Declare variables
logic [31:0] x, y, a = 10, b = 20;
initial begin
// Calculate x <= a+b
x = a + b;
// Calculate y <= a+b+10+x
y = a + b + 10 + x;
Endmodule
x = 30
y = 70
21. Write a systemverilog code to print numbers from 1 to 10 using loop statements
module print_numbers;
initial begin
for (int i = 1; i <= 10; i++) begin
$display("Number %0d", i);
end
end
endmodule
22. Discuss the nonblocking assignment of system Verilog and write a system Verilog code
to perform sum of two variables using nonblocking statements.
// Declare variables
logic [7:0] a = 4;
logic [7:0] b = 7;
logic [7:0] sum_reg;
always @* begin
sum_reg <= a + b;
end
initial begin
$display("Sum of %d and %d is %d", a, b, sum_reg);
end
endmodule
23. Write a systemverilog code for pass by value and pass by reference argument passing.
24. Explain the new jump statements and operators in system Verilog.
SystemVerilog has several new jump statements and operators that provide additional
functionality for controlling the flow of code. These new statements and operators
include:
1. Jump statements:
● return statement: The return statement is used to exit a function or
task and return a value to the caller. It can also be used to exit a void
function or task without returning a value.
● break statement: The break statement is used to exit a loop or switch
statement. It is typically used in conjunction with a conditional statement
to control when the loop or switch is exited.
● continue statement: The continue statement is used to skip to the next
iteration of a loop. It is typically used in conjunction with a conditional
statement to control when the loop is skipped.
2. Operators:
● ++ and -- operators: The ++ and -- operators are used to increment or
decrement a variable by one. They can be used as a prefix or postfix
operator.
● ?: operator: The ?: operator is a ternary operator that allows for
conditional expressions. It evaluates a condition and returns one value if
the condition is true and another value if the condition is false.
● inside operator: The inside operator is used to test if a value is within a
range of values. It is typically used in conjunction with a case or if
statement to test if a value is within a certain range.
module jump_and_operator_example;
return a + b;
endfunction
int i;
if (i == 5) begin
break;
end
end
endtask
int i;
End
endtask
initial begin
loop_with_break(10);
loop_with_continue(10);
// Test ?: operator
int a = 5, b = 7, max;
max = (a > b) ? a : b;
int value = 8;
end
endmodule
25. Using break statement in system verilog ,write the program for the following output:
Iteration [0]
Iteration [1]
Iteration [2]
Iteration [3]
Iteration [4]
Iteration [5]
module break_example;
initial begin
for (int i = 0; i < 10; i++) begin
$display("Iteration [%0d]", i);
if (i == 5) begin
$display("Breaking out of loop");
break;
end
end
end
endmodule
26. Using continue statement in system verilog , write the program for the following
output
Current value of a = 0
Current value of a = 1
Current value of a = 2
Current value of a = 3
Current value of a = 4
Current value of a = 5
Current value of a = 6
Current value of a = 7
Current value of a = 8
Current value of a = 9
module continue_example;
initial begin
for (int a = 0; a < 10; a++) begin
if (a == 5) begin
$display("Skipping a = 5");
continue;
end
$display("Current value of a = %0d", a);
end
end
endmodule