0
0
VHDLprogramming~10 mins

ALU design in VHDL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 4-bit input signal named 'A'.

VHDL
signal A : std_logic_vector([1] downto 0);
Drag options to blanks, or click blank then click option'
A7
B4
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 downto 0 which creates 5 bits instead of 4.
Using 7 downto 0 which is 8 bits.
2fill in blank
medium

Complete the code to perform bitwise AND on inputs A and B and assign to output Result.

VHDL
Result <= A [1] B;
Drag options to blanks, or click blank then click option'
Aand
Bor
Cxor
Dnand
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'or' instead of 'and'.
Using 'xor' which is exclusive or.
3fill in blank
hard

Fix the error in the process sensitivity list to include all inputs A, B, and Op.

VHDL
process([1])
begin
  -- ALU operation code
end process;
Drag options to blanks, or click blank then click option'
AA, B
BA
COp
DA, B, Op
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out 'Op' from the sensitivity list.
Including only one or two inputs.
4fill in blank
hard

Fill both blanks to complete the case statement for ALU operations.

VHDL
case Op is
  when "00" => Result <= A [1] B;
  when "01" => Result <= A [2] B;
  when others => Result <= (others => '0');
end case;
Drag options to blanks, or click blank then click option'
Aand
Bor
Cxor
Dnand
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping AND and OR operations.
Using XOR or NAND incorrectly.
5fill in blank
hard

Fill all three blanks to complete the ALU output assignment with addition and subtraction.

VHDL
case Op is
  when "10" => Result <= std_logic_vector(unsigned(A) [1] unsigned(B));
  when "11" => Result <= std_logic_vector(unsigned(A) [2] unsigned(B));
  when others => Result <= (others => '0');
end case;
-- Note: [3] is used for type conversion.
Drag options to blanks, or click blank then click option'
A+
B-
Cunsigned
Dstd_logic_vector
Attempts:
3 left
💡 Hint
Common Mistakes
Using std_logic_vector instead of unsigned for arithmetic.
Mixing up addition and subtraction operators.