移位寄存器如何进行二进制到bcd转换

How does the shift register work in binary to bcd conversion

我找到了这个 12 位二进制到 bcd 转换的代码,但我似乎无法理解移位寄存器部分(只显示状态机部分)。我需要帮助来理解“&”在移位寄存器中究竟是如何工作的,以及是否有人也可以为移位寄存器部分提供一种不同的方式,使其看起来像下面的代码,因为它更容易理解数据流:


    ishiftRegister(7) <= Rxd;

    ishiftRegister(6 downto 0) <= iShiftRegister(7 downto 1);


     -- State Machine
    process(present_state, binary, binary_in, bcd_temp, bcds_reg, shift_counter)
    begin
        next_state <= present_state;
        bcds_next <= bcd_temp;
        binary_next <= binary;
        shift_counter_next <= shift_counter;

        case present_state is

            when st_start =>
               next_state <= st_shift;
               binary_next <= binary_in;
               bcds_next <= (others => '0');
               shift_counter_next <= 0;

            when st_shift =>
                if shift_counter = 12 then
                    next_state <= st_stop;
                else
                    binary_next <= binary(10 downto 0) & 'L';
                    bcds_next <= bcds_reg(18 downto 0) & binary(11);
                    shift_counter_next <= shift_counter + 1;
                end if;

            when st_stop=>
                next_state <= st_start;

        end case;
    end process;

& 是一个串联运算符。例如,检查此问题以进行更多讨论:Concatenating bits in VHDL

bcds_next <= bcds_reg(18 downto 0) & binary(11);

使用 bcds_reg(18 downto 0) 时,您取出 bcds_reg 向量的 19 个最低有效位(并删除最高有效位)。 IE。寄存器向左移动。 binary(11) 是 12 位向量 binary 的最高有效位。使用 & 连接一个 19 位向量和一个位会创建一个 20 位向量,然后您可以将其分配给 20 位向量 bcds_next.

对于你的其他问题,我认为以下也是可能的,并且没有 & 运算符的相等操作。

bcds_next(19 downto 1) <= bcds_reg(18 downto 0);
bcds_next(0) <= binary(11);