Jump to content

Arithmetic logic unit: Difference between revisions

From Logic World Wiki
Rgjava (talk | contribs)
m added the alu example. :3
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
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|This is what a control line alu looks like it has inputs A and 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, often 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 could perform are arithmetic operations such as addition and subtraction, as well as bitwise operations like XOR, AND, and OR.
The ALU is a component in a computer that does the actal processing in a computer, it has an opcode input and inputs for A and B. Its like the brains of the computer. It can add two numbers or subtract two numbers. It can also do bitwise operations. Like XOR, NOR, AND, OR, is 0, is -, carry. It can do flags like A = B, A > B, A < B.


Example of what opcodes may look like:
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 [[Full Adder|adder]].
 
{{Todo|Improve this section, also add better images.}}
 
== 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:
 
{| class="wikitable"
! 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
|}
If your ALU only has arithmatic functions, it would be an Arithmatic Unit (AU). If your ALU only has logic functions, it would be a Logic Unit (LU).
{{Todo|Improve this section, without ai.}}
 
== 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 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:
{| class="wikitable"
{| class="wikitable"
|+
|+
!Name
!Operation
!Opcode
!Pins
!'''Description'''
!Description
|-
|-
|Add
|Add
|000
|None
|Adds A and B
|Adds A and B
|-
|-
|Sub
|Sub
|001
|Carry, !B
|Subtracts A and B
|Subtracts B from A
|-
|-
|AND
|AND
|010
|AND
|if A and B are true then output true else output false
|Outputs true if both A and B are true, otherwise false
|-
|-
|NAND
|NAND
|011
|!A, !B, AND
|invert of AND if A and B is true then output false
|Inverse of AND. If A and B are true, output is false
|-
|-
|OR
|OR
|100
|OR
|either A or B
|Outputs true if either A or B is true
|-
|-
|NOR
|NOR
|101
|!A, !B, OR
|invert of OR
|Inverse of OR. If either A or B is true, output is false
|-
|-
|XOR
|XOR
|110
|XOR
|OR of A and B but if both are true then output false
|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.{{Todo|Improve this section, WITHOUT AI.}}

Latest revision as of 19:44, 14 March 2026

This article is a stub. Please help expand it by adding content.
A symbolic representation of an ALU. The arrows represent inputs and outputs.
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, often 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 could perform are 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.


TODO: Improve this section, also add better images.

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

If your ALU only has arithmatic functions, it would be an Arithmatic Unit (AU). If your ALU only has logic functions, it would be a Logic Unit (LU).

TODO: Improve this section, without ai.

Multiplexer based ALU's

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 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. TODO: Improve this section, WITHOUT AI.