In the previous labs, we used to write our VHDL code in a dataflow style, which is a direct implementation on the gates level.
In this lab, we are going to write VHDL code using behavioural style, which means that we will write sequential statements in process in abstract level, which will be converted to logic gates.
But first, we will talk about the numeric package.
In this section, we are going to cover the numeric std package, which contains definitions and operations for numerical values, this will let us create numerical operations easily.
To use the package, you should use it:
You couldn't read bits as a number without deciding if it's unsigned or signed, in this package, we have both, but note that the signed is a 2's complement number.
Notice that the unsigned and signed is an array.
You could convert between std_logic_vector, unsigned, and signed using VHDL casting operation.
The casting operation is done by using the name of the type as a function because all these types are related (they all share the same building element std_logic
), they will be converted to each other easily.
Integers are numbers in VHDL, they are so different from signed and unsigned, the integers could be used to describe a numerical value for loops and other stuff.
To convert an integer to unsigned, we could use the to_unsigned
function, which will take the integer as its first argument, and the width as the second argument.
To convert an integer to signed, you could use to_signed
.
Converting an unsigned or signed number to an integer could be achieved using the to_integer
function, which will take the signal as its first argument.
To write code using behavioural style, you should create a process, the process itself is a concept in VHDL, which got executed concurrently (Nothing got executed, we are writing VHDL!).
The process got resolved when something in its sensitivity list changes, the sensitivity list is a list of singles.
Notice that our sensitivity list is (a, b)
, so any change in these signals will trigger our process.
Sequential statements will respect their order, they will be executed one after another, but the whole process will be executed concurrently.
Notice that we are saying executed, but this is a description language, so these are the rules that the synthesizer will assume when converting our statement to logic gates.
As you know an if statement is a conditional statement, which has the following syntax:
Notice that you could repeat elsif
as many as you want.
The case statement will create a multiplexer in most cases, but notice that we could assign more than one signal in each case.
std_logic_vector'
will create a vector from single bits.
Note: We will cover loops and more in the next lab!
You should create an ALU with the following functionality:
000
: a + b001
: a - b010
: -a011
: -b100
: b - a101
: a & b110
: a | b111
: !aNotice that a
and b
are 8-bit std_logic_vector, and should be treated as signed
with the numerical operations.
Create a testbench that covers at least one case in each operation.
VHDL
IUG