In this lab, we are going to talk about loops, how we could implement them, and what is the benefits of having loops in an HDL, then we will talk about variables, and understand how variables got synthesized into hardware.
Just like regular programming, loops will iterate over a sequential code for n times, we could create an infinite loop but it will not be synthesized.
The loop could be performed on a discrete type, and will termite after n iterations, or the use of exit
keyword.
The loop could cause the create components, and elements for each iteration, for example, you could use the loop to create multiple full adders.
So instead of repeating your hardware, you could describe the behaviour of your hardware, and the synthesizer will do the job.
Note that loops are sequential statements, so you could only use them inside a process.
To compare 4 bits, we will need to check the most significant bit first, so if we find that a is larger than b, or a is less than b, we will change the output and exit the loop, if the loop reacted zero, that means the first two conditions never become true, so a will be equal to b.
Note: Before the loop (at the process start), we reset all the outputs, but the signal won't change until the process got suspended.
In this example, we will use loops to test all possible values the comparator could take, notice that in the test bench you could do things that are not synthesizable.
In VHDL, we have two types of variables, normal and shared, normal variables can only be accessed from one process and are synthesizable, a shared variable can be used from multiple processes but are not synthesizable.
The variables are used inside a process, the variable will remember its value from the last execution of the process (you won't need that always), unlike singles a change to a variable will be present in the same execution cycle of the process.
In this example, we will generate a single bit, this bit will make the whole data have even parity.
Notice that we used a variable here because a signal won't change its values inside the loop.
TASK: what will happen if we removed line 15?
VHDL
IUG