In this lab, you will use Algorithmic State Machine with Datapath (ASMD) charts to implement algorithms as hardware circuits.
The implementation of algorithms in hardware is often performed by separating the data storage and manipulation components (the datapath circuit) from an FSM for the routing logic (the control circuit).
A key distinction between ASMD charts and flow charts is a concept known as implied timing. The implied timing specifies that all actions associated with the current state (i.e., the active path in the ASM block) take place only when the next active clock edge occurs. For a more thorough review of ASMD charts, see the lecture slides.
The ASMD chart shown in Figure 1 represents a circuit that counts the
number of bits set to 1
in an n-bit input A
(i.e., A
=
an-1an-2…a1a0).
Implement the bit-counting circuit given by the ASMD chart in Figure 1 in SystemVerilog to run on the DE1-SoC, combining the necessary datapath components and a control circuit FSM.
A
) connected to switches SW7–SW0
, a
synchronous reset connected to KEY0
, and a start
signal (s
) connected to KEY3
.
s
input.
1
's counted in
A
on the 7-segment display HEX0
, and
signal that the algorithm is finished by lighting up
LEDR9
.
Implement a binary search algorithm, which searches through an
unsigned array to locate an 8-bit value A
once
the user presses Start
.
A block diagram for the circuit is shown in Figure 2.
The binary search algorithm works on a sorted array. Rather than comparing each value in the array to the one being sought, we first look at the middle element and compare the sought value to the middle element. If the middle element has a greater value, then we know that the value we seek would be in the first half of the array. Otherwise, the value we seek would be in the second half of the array. By applying this approach recursively, we can complete our search in many fewer steps.
logic
is an unsigned data type in
SystemVerilog (i.e., the stored bits are interpreted by
their non-negative binary value).
Comparisons such as >
and <
are
unsigned comparisons on logic
values,
regardless of what radix you are using to display their value in
ModelSim.
For example, if logic [7:0] x = 8'd2;
, it turns out
that x > -1
returns false, because -1
is stored as 8'hFF
, which is interpreted as
255
in unsigned.
A
should be specified on switches
SW7–SW0
, Start
on KEY3
, and
Reset
on KEY0
.
Loc
, which specifies
the address in the memory where the number A
is
located, a signal Done
indicating that the algorithm
is finished, and a signal Found
that should be high if
A
was found and low otherwise.
Loc
, if found, in hex on
HEX1–HEX0
, Done
on
LEDR9
, and Found
on
LEDR0
.
Clock
input and be sure to synchronize the Start
input to
the clock (i.e., handle metastability).
SW9
.
Due by the end of Friday, submitted as a PDF on .
Due within one week of the lab report deadline, but typically during your assigned demo slot or a scheduled office hour.