Jump to content

Arithmetic logic unit: Difference between revisions

From Logic World Wiki
Rgjava (talk | contribs)
I added some basic explainations about the alu im going to add more stuff in this page in the future
 
Rgjava (talk | contribs)
m Fixed grammer mystakes.
 
(6 intermediate revisions by 2 users not shown)
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.]]
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.
[[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:


Example of what opcodes may look like:
{| class="wikitable"
! 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
|}
== ALU Designs ==
Their are two main alu Designs:
 
* Mux Based ALU's
* Control Line Based ALU's
=== Mux Based ALU's ===
[[File:Muxbased alu.jpg|thumb|266x266px|Simple Mux Based ALU]]
Mux based ALU's uses a [[Multiplexer]] to select outputs from gates or oprations
 
Pros:
 
* They are simple to make
* They are easy to understand
 
Cons:
 
* They take up alot of space
* They are limited in operations
 
=== Control Line Based ALU's ===
Unlike Mux Based ALU's, Control Line Based ALU's dont have a mux instead they have inputs like:
 
* Carry
* !A
* !B
* OR
* XOR
* AND
* NOR
 
They can do lots of operations. they dont have a sub mod input insread to subtract number you can turn on invert B (!B) and carry.
 
Note they dont have opcode input like mux based alus so you have to make a ROM that turns on specific pins like:
{| class="wikitable"
{| class="wikitable"
|+
|+
!Name
!Name
!Opcode
!Opcode
!'''Description'''
!Pins
!Description
|-
|-
|Add
|Add
|000
|0000
|None
|Adds A and B
|Adds A and B
|-
|-
|Sub
|Sub
|001
|0001
|Subtracts A and B
|Carry, !B
|Subtracts B from A
|-
|-
|AND
|AND
|010
|0010
|if A and B are true then output true else output false
|AND
|Outputs true if both A and B are true, otherwise false
|-
|-
|NAND
|NAND
|011
|0011
|invert of AND if A and B is true then output false
|!A, !B, AND
|Inverse of AND. If A and B are true, output is false
|-
|-
|OR
|OR
|100
|0100
|either A or B
|OR
|Outputs true if either A or B is true
|-
|-
|NOR
|NOR
|101
|0101
|invert of OR
|!A, !B, OR
|Inverse of OR. If either A or B is true, output is false
|-
|-
|XOR
|XOR
|110
|0110
|OR of A and B but if both are true then output false
|XOR
|Outputs true if exactly one of A or B is true
|-
|XNOR
|0111
|!A, !B, XOR
|Inverse of XOR Outputs true if exactly one of A or B is false
|-
|INC
|1000
|B = 1
|Increments A by 1
|-
|DEC
|1001
|Carry, !B, B = 1
|Decrements A by 1
|}
|}
Pros:
* They allow for complex oprations.
* They are small
Cons:
* They are complex

Latest revision as of 15:45, 14 September 2025

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.
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

ALU Designs

Their are two main alu Designs:

  • Mux Based ALU's
  • Control Line Based ALU's

Mux Based ALU's

Simple Mux Based ALU

Mux based ALU's uses a Multiplexer to select outputs from gates or oprations

Pros:

  • They are simple to make
  • They are easy to understand

Cons:

  • They take up alot of space
  • They are limited in operations

Control Line Based ALU's

Unlike Mux Based ALU's, Control Line Based ALU's dont have a mux instead they have inputs like:

  • Carry
  • !A
  • !B
  • OR
  • XOR
  • AND
  • NOR

They can do lots of operations. they dont have a sub mod input insread to subtract number you can turn on invert B (!B) and carry.

Note they dont have opcode input like mux based alus so you have to make a ROM that turns on specific pins like:

Name Opcode Pins Description
Add 0000 None Adds A and B
Sub 0001 Carry, !B Subtracts B from A
AND 0010 AND Outputs true if both A and B are true, otherwise false
NAND 0011 !A, !B, AND Inverse of AND. If A and B are true, output is false
OR 0100 OR Outputs true if either A or B is true
NOR 0101 !A, !B, OR Inverse of OR. If either A or B is true, output is false
XOR 0110 XOR Outputs true if exactly one of A or B is true
XNOR 0111 !A, !B, XOR Inverse of XOR Outputs true if exactly one of A or B is false
INC 1000 B = 1 Increments A by 1
DEC 1001 Carry, !B, B = 1 Decrements A by 1

Pros:

  • They allow for complex oprations.
  • They are small

Cons:

  • They are complex