In [1]:
from __future__ import division
from __future__ import print_function
from myhdl import Signal, intbv, always_seq
from support import vcd
from test_02_mex import test
%matplotlib inline
The goal of this exercise is to implement a module that calculates the greatest common divisor.
Two input signals: a
and b
are presented to the module, the start
strobe starts the calculation, the values present on a
and b
when start
is active are the values used to calculate the GCD. See the above link for various methods (algorithms) to calculate the GCD.
The number of clock cycles required to compute the GCD is not specified for this module. Because the clock cycles are not defined or indented to be static another mechanism is needed
In [2]:
def gcd(clock, reset, a, b, c, start, finished):
# example of handshaking, the finished is toggled
# after the start strobe.
@always_seq(clock.posedge, reset=reset)
def beh():
if start:
finished.next = False
elif not finished:
finished.next = True
return beh
In [3]:
test(gcd)
In [4]:
# VCD notebook plot is experimental ...
vcd.parse_and_plot('vcd/02_mex.vcd')
Out[4]:
In [ ]: