An arithmetic-logic unit is the part of a CPU. ALU is a digital circuit used to perform arithmetic and logic operations. It represents the fundamental building block of the central processing unit (CPU) of a computer. in ALU where all the processing happens and all mathematic calculations take place, such as addition, subtraction, multiplication, and division, as well as all the logical operations for decision making.
In some processors, the ALU is divided into two units: an arithmetic unit (AU) and a logic unit (LU).
How does an arithmetic-logic unit work?
the ALU has direct input and output access to the processor controller, main memory (RAM) and input/output devices. Inputs and outputs flow along an electronic path that is called a bus.
The following are a few examples of bitwise logical operations and basic arithmetic operations supported by ALUs:
Addition. Adds A and B with carry-in or carry-out sum at Y.
Subtraction. Subtracts B from A or vice versa with the difference at Y and carry-in or carry-out.
Increment. Where A or B is increased by one and Y represents the new value.
Decrement. Where A or B is decreased by one and Y represents the new value.
AND. The bitwise logic AND of A and B is represented by Y.
OR. The bitwise logic OR of A and B is represented by Y.
Exclusive-OR. The bitwise logic XOR of A and B is represented by Y.