bit to bit xor with same input vector in vhdl

你说的曾经没有我的故事 提交于 2020-01-15 10:09:02

问题


I want to do bit by bit xor with same input vector like:

input(0) xor input(2) xor input(3) up to input(187).

The answer I get is like:

output(0) downto output (94)

This means I have to do xor successively. If I have 10 input bits, the last answer I get is 5 bit output. Its very difficult and not a good approach to write the whole vector.

Does anyone knows how to write a efficient code of this in vhdl?

I have a idea how to do it. First extract even index bits, then odd index bits and do xor but no luck please help me.


回答1:


It sounds like you need either a generate statement or a for loop.

Concurrent Statement

lots_of_xor: for i in 0 to 94 generate
    output(i) <= input(2*i + 0) xor input(2*i + 1);
end generate;

Sequential Statement

for i in 0 to 94 loop
    output(i) <= input(2*i + 0) xor input(2*i + 1);
end loop;

Notes

In either version, we can replace 94 with output'length as well.



来源:https://stackoverflow.com/questions/25368402/bit-to-bit-xor-with-same-input-vector-in-vhdl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!