移位寄存器如何在二进制到bcd转换中工作

时间:2019-04-16 10:03:59

标签: binary vhdl data-conversion bcd

我发现此代码是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;

1 个答案:

答案 0 :(得分:0)

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

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

使用bcds_reg(18 downto 0),您将获得bcds_reg向量的19个最低有效位(并删除最高有效位)。即寄存器向左移动。 binary(11)是12位向量binary的最高有效位。将一个19位向量和一个单一位与&连接在一起,会创建一个20位向量,然后可以将其与20位向量bcds_next关联。

对于您的另一个问题,我认为以下操作也是可能的,并且在没有&运算符的情况下可以进行相等的操作。

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