我需要以数据流和控制的形式设计一个数字电路,以计算正数 N 的以 2 为底的对数的整个部分,在 VHDL 中表示为无符号 8 位整数。
基本上我会这样做:
int log2 (int N) {
int count = -1;
while (N>0){
N = N >> 1;
count++
}
return count;
}
我将使用 8 位整数来表示数字 N,并在右侧错位为 0。那么,位错数减1,等于log2。
我已经创建了实体:
entity log2 is
port (
clock, reset: in bit; -- global control: clock and reset
start: in bit;
ready: out bit; -- finished execution (equal to 1 when the calculation is finished)
N: in bit_vector(7 downto 0);
logval: out bit_vetor(3 downto 0) -- log2(N)
);
end entity log2;
但我在以下过程中苦苦挣扎。
我制作了一个 ASM 图来提供帮助,它是:
而且我也知道我需要一些数据流元素,例如:
- 对于“reg”,我需要一个移位寄存器,
- 对于日志,我需要一个计数器寄存器
我只能在理论上看到这一点,我正在努力将所有这些都放入代码中。
有人知道我该如何开始架构吗?