Lab 4 VXL
Lab 4 VXL
hardware description
language (cont)
Assignments
Continous assignment:
- Continuous assignments continuously monitor the RHS (right – hand side) and update the LHS (left –
hand side) immediately when the RHS change, does not introduce any timing delays.
- Multiple continous assignment executes concurrently, order of statements is not important.
- Used outside always statement to design simple combinational circuit.
- Syntax: assign LHS = RHS;
Blocking assignment:
- Cause the RHS expression to be evaluated immediately, and the LHS variable is updated before moving
to the next statement.
- Multiple blocking assignments are executed sequentially in the order they appear in the code, order of
statements is important.
- Used inside always statement to design combinational circuit.
- Syntax: LHS = RHS;
- always statement can be used to design flip-flop, latches or combinational circuit depend on
the sensitivity list and statement.
+ always @(sensitivity list) can be used to design sequential or combinational circuit based
on sensitivity list
Ex: To design full adder: always@(a, b, cin)
To design D flip-flop: always@(posedge clk)
+ always_comb: is dedicated for designing combinational circuit; reevaluates the statements
inside always_comb any time the signal on RHS of statement changes.
+ always_latch is dedicated for design latch
+ always_ff is dedicated for design flip flop
Example on fulladder
Example: design a fulladder using always_comb statement
Size/dimension to the left of variable name Size/dimension to the right of variable name
Declaration Ex: logic [3:0] data_bus; // 4 bits packed Ex: logic flag[3:0]; // 4 independent 1-bit logic
together variables
Storage Contiguous block of bits (compact in memory) Independent elements (not contiguous in memory)
Usage Represents multi-bit data like vectors, buses Represents independent variables (like arrays)
Bitwise Supported (since elements are bits) Not directly supported (need to access each element
Operations individually)
Arithmetic Supported (treats entire array as a number) Not directly supported for the entire array
Operations
Example:
// Packed Array: Represents a 4-bit bus or vector
logic [3:0] data_bus; // 4 bits packed together
module inverter(input logic [3:0] a, output logic [3:0] b);
// Unpacked Array: Array of independent variables
logic flag[3:0]; // 4 independent 1-bit logic variables
SystemVerilog numbers
- The format for declaring constants is N'Bvalue, where N is the
size in bits, B is a letter indicating the base, and value gives the
value.
- SystemVerilog supports 'b for binary, 'o for octal, 'd for decimal,
and ‘h for hexadecimal. If the base is omitted, it defaults
to decimal.
If-else statement
The syntax for an if-else statement in SystemVerilog is very similar to other programming languages
like C or Verilog. It is used to execute different blocks of code based on a conditional expression.
Syntax:
if (condition) begin
// Code to execute if condition is true
end else begin
// Code to execute if condition is false
end
default:
begin
// Code block to execute when expression doesn't match any value
// ...
end
endcase
Opcode Operation
000 Add
001 Substract
010 And
011 Or
100 Xor
101 Equal