Arithmetic operators help you do math with numbers in your VHDL code. They let you add, subtract, multiply, and divide values.
0
0
Arithmetic operators in VHDL
Introduction
When you want to add two signals or variables.
When you need to subtract one value from another.
When you want to multiply numbers for calculations.
When you need to divide one number by another.
When you want to calculate the remainder after division.
Syntax
VHDL
result := operand1 + operand2; -- addition result := operand1 - operand2; -- subtraction result := operand1 * operand2; -- multiplication result := operand1 / operand2; -- division result := operand1 mod operand2; -- modulus (remainder)
Operands must be of compatible numeric types like integer or unsigned.
Use 'mod' for remainder after division, not the '%' symbol.
Examples
Adds values of a and b and stores in sum.
VHDL
sum := a + b;Subtracts y from x and stores in difference.
VHDL
difference := x - y;
Multiplies m and n and stores in product.
VHDL
product := m * n;
Calculates remainder of value divided by divisor.
VHDL
remainder := value mod divisor;
Sample Program
This program shows how to use arithmetic operators with integers in VHDL. It calculates sum, difference, product, quotient, and remainder of two signals and reports the results.
VHDL
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity ArithmeticDemo is end ArithmeticDemo; architecture Behavioral of ArithmeticDemo is signal a, b : integer := 10; signal sum, diff, prod, quot, rem : integer; begin process begin sum <= a + b; diff <= a - b; prod <= a * b; quot <= a / b; rem <= a mod b; wait for 10 ns; report "Sum: " & integer'image(sum); report "Difference: " & integer'image(diff); report "Product: " & integer'image(prod); report "Quotient: " & integer'image(quot); report "Remainder: " & integer'image(rem); wait; end process; end Behavioral;
OutputSuccess
Important Notes
Division by zero causes an error, so ensure divisor is not zero.
Use ieee.numeric_std package for arithmetic on unsigned and signed types.
Arithmetic operators work on integers and numeric types, not on std_logic directly.
Summary
Arithmetic operators perform basic math in VHDL.
Use +, -, *, / for add, subtract, multiply, divide.
Use mod to get the remainder after division.