From the course: Learning Verilog for FPGA Development
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
The if-else statement - FPGA Tutorial
From the course: Learning Verilog for FPGA Development
The if-else statement
- [Instructor] In this example, I'll show you an implementation of a two-to-one multiplexer module like the one you see in this schematic. It has two inputs in a bus named I, one selection input and an output Y. Here is the code for the multiplexer module starting at line 23. It's called mux_2_to_1. Notice that Y is declared as a register because of the way I'm using it in the following lines of code. So the code consists of a single always statement starting at line 29 which is sensitive to changes in the selection input and the input bus I. As with most statements, if the always block applies to more than one line of code, the block must be enclosed between the begin and end keywords as you can see in this example. What will be evaluated whenever sel or I change is an if-then statement. Here we are checking if the selection input is zero. If so, we are saying the input I[0] to the output. Otherwise, we are saying the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Verilog modules4m 13s
-
(Locked)
Instantiating modules4m 49s
-
(Locked)
Gates and primitives3m 3s
-
(Locked)
Registers and wires1m 46s
-
(Locked)
Range specification4m 30s
-
(Locked)
Numbers and constants4m 53s
-
(Locked)
Always blocks52s
-
(Locked)
The if-else statement2m 2s
-
(Locked)
Case statements2m 24s
-
(Locked)
Boolean algebra expressions56s
-
(Locked)
Continuous assignments2m 23s
-
(Locked)
Blocking assignments3m 20s
-
(Locked)
Nonblocking assignments3m 49s
-
(Locked)
Challenge: From schematic to code2m 16s
-
(Locked)
Solution: From schematic to code4m 31s
-
-
-
-
-