Arithmetic logic unit: Difference between revisions
Appearance
m added the alu example. :3 |
Tweaks to the article |
||
Line 1: | Line 1: | ||
[[File:ALU.gif|thumb|A symbolic representation of an ALU. The arrows represent inputs and outputs.]] | [[File:ALU.gif|thumb|A symbolic representation of an ALU. The arrows represent inputs and outputs.]] | ||
[[File:Alu-8-bit.png|thumb| | [[File:Alu-8-bit.png|thumb|An 8-bit ALU with inputs A, B, !A, !B, Carry, XOR, AND, OR.]] | ||
{{ALU}} | |||
:It may be called the "brains" of the [[CPU|central processor]]. | |||
An ALU also has "flags" to keep track of different situations during computation. | |||
Operations that an ALU can perform include arithmetic operations such as addition and subtraction, as well as ''bitwise'' operations like XOR, NOR, AND, and OR. | |||
The status flags it keeps track of are, for example: | |||
* ''A = B'' | |||
* ''A > B'' | |||
* ''A < B'' | |||
* Carry | |||
* Others | |||
ALUs can have very different designs with varying specifications, such as bit size, possible operations, and speed. In principle, you don't need to implement every possible operation - a few operations are sufficient to make the system Turing complete - although additional operations make it more convenient and often faster. | |||
== Example == | |||
Below is an example of possible operations in an ALU: | |||
{| class="wikitable" | {| class="wikitable" | ||
! Name | |||
!Name | ! Opcode | ||
!Opcode | ! Description | ||
! | |||
|- | |- | ||
|Add | | Add | ||
|000 | | 000 | ||
|Adds A and B | | Adds A and B | ||
|- | |- | ||
|Sub | | Sub | ||
|001 | | 001 | ||
|Subtracts A | | Subtracts B from A | ||
|- | |- | ||
|AND | | AND | ||
|010 | | 010 | ||
|if A and B are true | | Outputs true if both A and B are true, otherwise false | ||
|- | |- | ||
|NAND | | NAND | ||
|011 | | 011 | ||
| | | Inverse of AND. If A and B are true, output is false | ||
|- | |- | ||
|OR | | OR | ||
|100 | | 100 | ||
|either A or B | | Outputs true if either A or B is true | ||
|- | |- | ||
|NOR | | NOR | ||
|101 | | 101 | ||
| | | Inverse of OR. If either A or B is true, output is false | ||
|- | |- | ||
|XOR | | XOR | ||
|110 | | 110 | ||
| | | Outputs true if exactly one of A or B is true | ||
|} | |} |
Revision as of 14:23, 14 September 2025


- Arithmetic logic unit
- In Logic World, an arithmetic logic unit (ALU) is a component of a central processor that performs basic arithmetic and logic operations.
- By combining multiple operations, it is possible to perform any computation.
- It may be called the "brains" of the central processor.
An ALU also has "flags" to keep track of different situations during computation. Operations that an ALU can perform include arithmetic operations such as addition and subtraction, as well as bitwise operations like XOR, NOR, AND, and OR.
The status flags it keeps track of are, for example:
- A = B
- A > B
- A < B
- Carry
- Others
ALUs can have very different designs with varying specifications, such as bit size, possible operations, and speed. In principle, you don't need to implement every possible operation - a few operations are sufficient to make the system Turing complete - although additional operations make it more convenient and often faster.
Example
Below is an example of possible operations in an ALU:
Name | Opcode | Description |
---|---|---|
Add | 000 | Adds A and B |
Sub | 001 | Subtracts B from A |
AND | 010 | Outputs true if both A and B are true, otherwise false |
NAND | 011 | Inverse of AND. If A and B are true, output is false |
OR | 100 | Outputs true if either A or B is true |
NOR | 101 | Inverse of OR. If either A or B is true, output is false |
XOR | 110 | Outputs true if exactly one of A or B is true |