Arithmetic logic unit: Difference between revisions
mNo edit summary |
FoxFireFive (talk | contribs) Fixed the article by mostly re-writting it. PLEASE STOP USING AI FOR THE LOVE OF ALL THAT'S HOLY. IF YOU CAN'T EDIT WITHOUT AI, DON'T EDIT!! |
||
| Line 1: | Line 1: | ||
[[File:ALU.gif|thumb|A symbolic representation of an ALU. The arrows represent inputs and outputs.]] | {{Stub}}[[File:ALU.gif|thumb|A symbolic representation of an ALU. The arrows represent inputs and outputs.]] | ||
[[File:Alu-8-bit.png|thumb|An 8-bit ALU with inputs A, B, !A, !B, Carry, XOR, AND, OR.]] | [[File:Alu-8-bit.png|thumb|An 8-bit ALU with inputs A, B, !A, !B, Carry, XOR, AND, OR.]]An Arithmetic Logic Unit (ALU) is a circuit that performs basic arithmetic and logic operations, usually used in CPUs. They usually have "flags" to keep track of different things during execution, like if the result overflowed, or the result was zero. Flags are usually implemented with flip-flops. Operations that an ALU can perform include arithmetic operations such as addition and subtraction, as well as bitwise operations like XOR, AND, and OR. | ||
The different kinds of flags an ALU could keep track of are: | |||
* If "A" is equal to "B" | |||
* If "A" is lesser than "B" | |||
* If "A" is greater than "B" | |||
* If the carry bit was set during execution. | |||
The | The carry bit is usually the "Carry-out" part of an [[Full Adder|adder]]. | ||
{{Todo|Improve this section, also add better images.}} | |||
== | == ALU Designs and operations == | ||
Below | ALUs can have many different designs with varying specifications, such as bit width, operations, size, and speed. Below are a few operations an ALU could have: | ||
{| class="wikitable" | {| class="wikitable" | ||
! | ! Operation | ||
! Description | ! Description | ||
|- | |- | ||
| Add | | Add | ||
| Adds A and B | | Adds A and B | ||
|- | |- | ||
| Sub | | Sub | ||
| Subtracts B from A | | Subtracts B from A | ||
|- | |- | ||
| AND | | AND | ||
| Outputs true if both A and B are true, otherwise false | | Outputs true if both A and B are true, otherwise false | ||
|- | |- | ||
| NAND | | NAND | ||
| Inverse of AND. If A and B are true, output is false | | Inverse of AND. If A and B are true, output is false | ||
|- | |- | ||
| OR | | OR | ||
| Outputs true if either A or B is true | | Outputs true if either A or B is true | ||
|- | |- | ||
| NOR | | NOR | ||
| Inverse of OR. If either A or B is true, output is false | | Inverse of OR. If either A or B is true, output is false | ||
|- | |- | ||
| XOR | | XOR | ||
| Outputs true if exactly one of A or B is true | | Outputs true if exactly one of A or B is true | ||
|} | |} | ||
{{Todo|Improve this section, without ai. | |||
man I am so tired its 6:18am and i just want to go to bed.}} | |||
== Multiplexer based ALU's == | |||
[[File:Muxbased alu.jpg|thumb|266x266px|Simple multiplexer based ALU]] | |||
Multiplexer based ALU's use a [[Multiplexer]] to select outputs from their different operations. | |||
They are fairly easy to make, and usually easy to understand, but can take up a lot of space, and are limited in operations. | |||
{{Todo|Explain mux ALUs more. WITHOUT THE USE OF AI.}} | |||
== Control line based ALU's == | |||
Unlike Mux Based ALU's, Control Line Based ALU's don't have a | Unlike Mux Based ALU's, Control Line Based ALU's don't have a multiplexer, instead they have inputs like: | ||
* Carry | * Carry | ||
| Line 82: | Line 62: | ||
* NOR | * NOR | ||
They can do lots of operations. They don't have a | They can do lots of operations. They don't have a subtract mode input, instead you can turn on "Invert B" (!B) and carry to perform subtraction. | ||
Note they don't have opcode input like | Note that they don't have an opcode input like multiplexer based ALUs, so you have to make a ROM that turns on specific pins like: | ||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
! | !Operation | ||
!Pins | !Pins | ||
!Description | !Description | ||
|- | |- | ||
|Add | |Add | ||
|None | |None | ||
|Adds A and B | |Adds A and B | ||
|- | |- | ||
|Sub | |Sub | ||
|Carry, !B | |Carry, !B | ||
|Subtracts B from A | |Subtracts B from A | ||
|- | |- | ||
|AND | |AND | ||
|AND | |AND | ||
|Outputs true if both A and B are true, otherwise false | |Outputs true if both A and B are true, otherwise false | ||
|- | |- | ||
|NAND | |NAND | ||
|!A, !B, AND | |!A, !B, AND | ||
|Inverse of AND. If A and B are true, output is false | |Inverse of AND. If A and B are true, output is false | ||
|- | |- | ||
|OR | |OR | ||
|OR | |OR | ||
|Outputs true if either A or B is true | |Outputs true if either A or B is true | ||
|- | |- | ||
|NOR | |NOR | ||
|!A, !B, OR | |!A, !B, OR | ||
|Inverse of OR. If either A or B is true, output is false | |Inverse of OR. If either A or B is true, output is false | ||
|- | |- | ||
|XOR | |XOR | ||
|XOR | |XOR | ||
|Outputs true if exactly one of A or B is true | |Outputs true if exactly one of A or B is true | ||
|- | |- | ||
|XNOR | |XNOR | ||
|!A, !B, XOR | |!A, !B, XOR | ||
|Inverse of XOR Outputs true if exactly one of A or B is false | |Inverse of XOR Outputs true if exactly one of A or B is false | ||
|- | |- | ||
|INC | |INC | ||
|B = 1 | |B = 1 | ||
|Increments A by 1 | |Increments A by 1 | ||
|- | |- | ||
|DEC | |DEC | ||
|Carry, !B, B = 1 | |Carry, !B, B = 1 | ||
|Decrements A by 1 | |Decrements A by 1 | ||
|} | |} | ||
They allow for complex operations, and are usually small, but can be complex and difficult to build.{{Todo|Improve this section, WITHOUT AI.}} | |||
Revision as of 10:21, 14 March 2026


An Arithmetic Logic Unit (ALU) is a circuit that performs basic arithmetic and logic operations, usually used in CPUs. They usually have "flags" to keep track of different things during execution, like if the result overflowed, or the result was zero. Flags are usually implemented with flip-flops. Operations that an ALU can perform include arithmetic operations such as addition and subtraction, as well as bitwise operations like XOR, AND, and OR.
The different kinds of flags an ALU could keep track of are:
- If "A" is equal to "B"
- If "A" is lesser than "B"
- If "A" is greater than "B"
- If the carry bit was set during execution.
The carry bit is usually the "Carry-out" part of an adder.
ALU Designs and operations
ALUs can have many different designs with varying specifications, such as bit width, operations, size, and speed. Below are a few operations an ALU could have:
| Operation | Description |
|---|---|
| Add | Adds A and B |
| Sub | Subtracts B from A |
| AND | Outputs true if both A and B are true, otherwise false |
| NAND | Inverse of AND. If A and B are true, output is false |
| OR | Outputs true if either A or B is true |
| NOR | Inverse of OR. If either A or B is true, output is false |
| XOR | Outputs true if exactly one of A or B is true |
Multiplexer based ALU's

Multiplexer based ALU's use a Multiplexer to select outputs from their different operations.
They are fairly easy to make, and usually easy to understand, but can take up a lot of space, and are limited in operations.
Control line based ALU's
Unlike Mux Based ALU's, Control Line Based ALU's don't have a multiplexer, instead they have inputs like:
- Carry
- !A
- !B
- OR
- XOR
- AND
- NOR
They can do lots of operations. They don't have a subtract mode input, instead you can turn on "Invert B" (!B) and carry to perform subtraction.
Note that they don't have an opcode input like multiplexer based ALUs, so you have to make a ROM that turns on specific pins like:
| Operation | Pins | Description |
|---|---|---|
| Add | None | Adds A and B |
| Sub | Carry, !B | Subtracts B from A |
| AND | AND | Outputs true if both A and B are true, otherwise false |
| NAND | !A, !B, AND | Inverse of AND. If A and B are true, output is false |
| OR | OR | Outputs true if either A or B is true |
| NOR | !A, !B, OR | Inverse of OR. If either A or B is true, output is false |
| XOR | XOR | Outputs true if exactly one of A or B is true |
| XNOR | !A, !B, XOR | Inverse of XOR Outputs true if exactly one of A or B is false |
| INC | B = 1 | Increments A by 1 |
| DEC | Carry, !B, B = 1 | Decrements A by 1 |
They allow for complex operations, and are usually small, but can be complex and difficult to build.