What is the function of the below code? [code]ENTITY my_logic IS PORT (din : STD_LOGIC_VECTOR(7 DOWNTO 0); Count : STD_LOGIC_VECTOR

Trang Mắm

New member
What is the function of the below code?
Code:
ENTITY my_logic IS
PORT (din : STD_LOGIC_VECTOR(7 DOWNTO 0);
             Count : STD_LOGIC_VECTOR(3 DOWNTO 0));
END my_logic;
ARCHITECTURE behavior OF my_logic IS
BEGIN
Count <= “0000”
PROCESS(din)
BEGIN
L1: FOR i IN 0 TO 7 LOOP
IF(din(i) = ‘1’) THEN
Count = count+1;
ELSE
NEXT L1;
END LOOP;
END PROCESS;
END behavior;
A. To count number of ones in the given data
B. To count number of zeroes in the given data
C. To reverse the order of given data
D. To perform binary multiplication of two data inputs
 
Answer: a
Explanation: Because a loop is used and din is monitored for every bit. If any bit in the din is one then the counter is incremented by one. Therefore, the code is counting the number of ones in a given vector of bits.
 

Tìm kiếm

Back
Top