Skip to main content

Posts

Showing posts from January, 2008

Behavioral Modeling

>> Introduction >> The initial Construct >> The always Construct >> Procedural Assignments >> Block Statements >> Conditional (if-else) Statement >> Case Statement >> Loop Statements >> Examples Introduction Behavioral modeling is the highest level of abstraction in the Verilog HDL. The other modeling techniques are relatively detailed. They require some knowledge of how hardware, or hardware signals work. The abstraction in this modeling is as simple as writing the logic in C language. This is a very powerful abstraction technique. All that designer needs is the algorithm of the design, which is the basic information for any design. Most of the behavioral modeling is done using two important constructs: initial and always. All the other behavioral statements appear only inside these two structured procedure constructs. The initial Construct The statements which come under the initial construct constitute the initial block. The in

Tasks and Functions

>> Introduction >> Differences >> Tasks >> Functions >> Examples Introduction Tasks and functions are introduced in the verilog, to provide the ability to execute common procedures from different places in a description. This helps the designer to break up large behavioral designs into smaller pieces. The designer has to abstract the similar pieces in the description and replace them either functions or tasks. This also improves the readability of the code, and hence easier to debug. Tasks and functions must be defined in a module and are local to the module. Tasks are used when: There are delay, timing, or event control constructs in the code. There is no input. There is zero output or more than one output argument. Functions are used when: The code executes in zero simulation time. The code provides only one output(return value) and has at least one input. There are no delay, timing, or event control constructs. Differences Functions Tasks Can enabl

Dataflow Modeling

>> Introduction >> The assign Statement >> Delays >> Examples Introduction Dataflow modeling is a higher level of abstraction. The designer no need have any knowledge of logic circuit. He should be aware of data flow of the design. The gate level modeling becomes very complex for a VLSI circuit. Hence dataflow modeling became a very important way of implementing the design. In dataflow modeling most of the design is implemented using continuous assignments, which are used to drive a value onto a net. The continuous assignments are made using the keyword assign . The assign statement The assign statement is used to make continuous assignment in the dataflow modeling. The assign statement usage is given below: assign out = in0 + in1; // in0 + in1 is evaluated and then assigned to out. Note: The LHS of assign statement must always be a scalar or vector net or a concatenation. It cannot be a register. Continuous statements are always active statements. Registers o

Gate-Level Modeling

>> Introduction >> Gate Primitives >> Delays >> Examples Introduction In Verilog HDL a module can be defined using various levels of abstraction. There are four levels of abstraction in verilog. They are: Behavioral or algorithmic level: This is the highest level of abstraction. A module can be implemented in terms of the design algorithm. The designer no need to have any knowledge of hardware implementation. Data flow level: In this level the module is designed by specifying the data flow. Designer must how data flows between various registers of the design. Gate level: The module is implemented in terms of logic gates and interconnections between these gates. Designer should know the gate-level diagram of the design. Switch level: This is the lowest level of abstraction. The design is implemented using switches/transistors. Designer requires the knowledge of switch-level implementation details. Gate-level modeling is virtually the lowest-level of abstraction,

Scheduling

The Verilog HDL is defined in terms of a discrete event execution model. A design consists of connected processes. Processes are objects that can be evaluated, that may have state, and that can respond to changes on their inputs to produce outputs. Processes include primitives, modules, initial and always procedural blocks, continuous assignments, asynchronous tasks, and procedural assignment statements. The following definitions helps in better understanding of scheduling and execution of events: Update event : Every change in value of a net or variable in the circuit being simulated, as well as the named event, is considered as an update event. Evaluation event : Processes are sensitive to update events. When an update event is executed, all the processes that are sensitive to that event are evaluated in an arbitrary order. The evaluation of a process is also an event, known as an evaluation event. Simulation time: It is used to refer to the time value maintained by the simulator to

List of Operators

>> Logical Operators >> Relational Operators >> Equality Operators >> Arithmetic Operators >> Bitwise Operators >> Reduction Operators >> Shift Operators >> Conditional Operators >> Replication Operators >> Concatenation Operators >> Operator Precedence Logical Operators Symbol Description #Operators ! Logical negation One || Logical OR Two && Logical AND Two Relational Operators Symbol Description #Operators > Greater than Two < Less than Two >= Greater than or equal to Two <= Less than or equal to Two Equality Operators Symbol Description #Operators == Equality Two != Inequality Two === Case equality Two !== Case inequality Two Arithmetic Operators Symbol Description #Operators + Add Two - Substract Two * Multiply Two / Divide Two ** Power Two % Modulus Two Bitwise Operators Symbol Description #Operators ~ Bit

Basics: Data Types

>> Value Set >> Nets >> Registers >> Integers >> Real Numbers >> Parameters >> Vectors >> Arrays >> Strings >> Time Data Type Value Set The Verilog HDL value set consists of four basic values: 0 - represents a logic zero, or a false condition. 1 - represents a logic one, or a true condition. x - represents an unknown logic value. z - represents a high-impedance state. The values 0 and 1 are logical complements of one another. Almost all of the data types in the Verilog HDL store all four basic values. Nets Nets are used to make connections between hardware elements. Nets simply reflect the value at one end(head) to the other end(tail). It means the value they carry is continuously driven by the output of a hardware element to which they are connected to. Nets are generally declared using the keyword wire . The default value of net (wire) is z. If a net has no driver, then its value is z . Registers Registers are data storage e

Ports

Modules communicate with external world using ports. They provide interface to the modules. A module definition contains list of ports. All ports in the list of ports must be declared in the module, ports can be one the following types: Input port, declared using keyword input . Output port, declared using keyword output . Bidirectional port, declared using keyword inout . All the ports declared are considered to be as wire by default. If a port is intended to be a wire, it is sufficient to declare it as output , input , or inout . If output port holds its value it should be declared as reg type. Ports of type input and inout cannot be declared as reg because reg variables hold values and input ports should not hold values but simply reflect the changes in the external signals they are connected to. Port Connection Rules Inputs: Always of type net ( wire ). Externally, they can be connected to reg or net type variable. Outputs: Can be of reg or net type. Externally, they must

Modules

A module is the basic building block in Verilog HDL. In general many elements are grouped to form a module, to provide a common functionality, which can be used at many places in the design. Port interface (using input and output ports) helps in providing the necessary functionality to the higher-level blocks. Thus any design modifications at lower level can be easily implemented without affecting the entire design code. The structure of a module is show in the figure below. Keyword module is used to begin a module and it ends with the keyword endmodule . The syntax is as follows: module module_name --- // internals --- endmodule Example: D Flip-flop implementation (Try to understand the module structure, ignore unknown constraints/statements). module D_FlipFlop (q, d, clk, reset); // Port declarations output q; reg q; input d, clk, reset; // Internal statements - Logic always @(posedge reset or poseedge clk) if (reset) q < = 1'b0; else q < = d; // endmodule statement endmo

Verilog Interview Questions - 2

1. Given the following Verilog code, what value of "a" is displayed? always @(clk) begin a = 0; a < = 1; $display(a); end Answer Verilog used four-level deep queue for the current simulation time: 1. Active events (blocking statements). 2. Inactive events (#0 delays, etc). 3. Non-blocking assign updates (non-blocking statements). 4. Monitor Events ($display, $monitor). So $display(a); displays 0. 2. What is the difference between a = #10 b; and #10 a = b; ? Answer In a = #10 b; current value of "b" will be assigned to "a" after 10 units of time (like transport delay). In #10 a = b; the simulator will execute a = b; after 10 units of time (like inertial delay). 3. Let "a" be a 3 bit reg value. initial begin a < = 3'b101; a = #5 3'b000; a < = #10 3'b111; a < = #30 3'b011; a = #20 3'b010; a < = #5 3'b110; end What will be the value of "a" at time 0,5,10,... units till 40 units of time? Answer 0 - 101

Microprocessor Interview Questions - 2

1. What is Program counter? Answer Program counter holds the address of either the first byte of the next instruction to be fetched for execution or the address of the next byte of a multi byte instruction, which has not been completely fetched. In both the cases it gets incremented automatically one by one as the instruction bytes get fetched. Also Program register keeps the address of the next instruction. 2. Do 8085(8-bit processor) have any 16 bit registers? Answer Yes, Stack pointer and Program counter are 16 bit registers. 3. What type of Stack is used in 8085? Answer LIFO (Last In First Out) stack is used in 8085. In this type of Stack the last pushed byte will be popped first. 4. What is HLT? Answer In x86 architecture, HLT is an assembly language instruction which halts the CPU until the next external interrupt is fired. The Micro Processor enters into halt-state and the buses are tri-stated. 5. What is a bus? Answer A bus is a group of conducting lines which carry data, addre