contur2
Loading...
Searching...
No Matches

Arithmetic Logic Unit — performs all computational operations. More...

#include <alu.h>

Public Member Functions

 ALU ()=default
 ~ALU ()=default
 ALU (const ALU &)=default
ALUoperator= (const ALU &)=default
 ALU (ALU &&) noexcept=default
ALUoperator= (ALU &&) noexcept=default
Result< RegisterValueadd (RegisterValue a, RegisterValue b) const noexcept
 Addition: a + b.
Result< RegisterValuesub (RegisterValue a, RegisterValue b) const noexcept
 Subtraction: a - b.
Result< RegisterValuemul (RegisterValue a, RegisterValue b) const noexcept
 Multiplication: a * b.
Result< RegisterValuediv (RegisterValue a, RegisterValue b) const noexcept
 Division: a / b.
Result< RegisterValuebitwiseAnd (RegisterValue a, RegisterValue b) const noexcept
 Bitwise AND: a & b.
Result< RegisterValuebitwiseOr (RegisterValue a, RegisterValue b) const noexcept
 Bitwise OR: a | b.
Result< RegisterValuebitwiseXor (RegisterValue a, RegisterValue b) const noexcept
 Bitwise XOR: a ^ b.
Result< RegisterValueshiftLeft (RegisterValue a, RegisterValue b) const noexcept
 Left shift: a << b.
Result< RegisterValueshiftRight (RegisterValue a, RegisterValue b) const noexcept
 Right shift: a >> b (arithmetic shift).
RegisterValue compare (RegisterValue a, RegisterValue b) const noexcept
 Compares two values and returns a flags word.

Static Public Attributes

static constexpr RegisterValue ZERO_FLAG = 1
 a == b
static constexpr RegisterValue SIGN_FLAG = 2
 a < b

Detailed Description

Arithmetic Logic Unit — performs all computational operations.

The ALU is owned by the CPU and invoked during the execute phase of the fetch-decode-execute cycle. All methods are pure functions: they take operands and return results without side effects.

Definition at line 20 of file alu.h.

Constructor & Destructor Documentation

◆ ALU() [1/3]

contur::ALU::ALU ( )
default

◆ ~ALU()

contur::ALU::~ALU ( )
default

◆ ALU() [2/3]

contur::ALU::ALU ( const ALU & )
default

◆ ALU() [3/3]

contur::ALU::ALU ( ALU && )
defaultnoexcept

Member Function Documentation

◆ add()

Result< RegisterValue > contur::ALU::add ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Addition: a + b.

◆ bitwiseAnd()

Result< RegisterValue > contur::ALU::bitwiseAnd ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Bitwise AND: a & b.

◆ bitwiseOr()

Result< RegisterValue > contur::ALU::bitwiseOr ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Bitwise OR: a | b.

◆ bitwiseXor()

Result< RegisterValue > contur::ALU::bitwiseXor ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Bitwise XOR: a ^ b.

◆ compare()

RegisterValue contur::ALU::compare ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Compares two values and returns a flags word.

The returned value encodes comparison flags:

  • Bit 0 (ZERO_FLAG): set if a == b
  • Bit 1 (SIGN_FLAG): set if a < b (signed comparison)
Returns
A flags word (never fails).

◆ div()

Result< RegisterValue > contur::ALU::div ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Division: a / b.

Returns
DivisionByZero error if b == 0.

◆ mul()

Result< RegisterValue > contur::ALU::mul ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Multiplication: a * b.

◆ operator=() [1/2]

ALU & contur::ALU::operator= ( ALU && )
defaultnoexcept

◆ operator=() [2/2]

ALU & contur::ALU::operator= ( const ALU & )
default

◆ shiftLeft()

Result< RegisterValue > contur::ALU::shiftLeft ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Left shift: a << b.

◆ shiftRight()

Result< RegisterValue > contur::ALU::shiftRight ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Right shift: a >> b (arithmetic shift).

◆ sub()

Result< RegisterValue > contur::ALU::sub ( RegisterValue a,
RegisterValue b ) const
nodiscardnoexcept

Subtraction: a - b.

Member Data Documentation

◆ SIGN_FLAG

RegisterValue contur::ALU::SIGN_FLAG = 2
staticconstexpr

a < b

Definition at line 78 of file alu.h.

◆ ZERO_FLAG

RegisterValue contur::ALU::ZERO_FLAG = 1
staticconstexpr

a == b

Definition at line 77 of file alu.h.


The documentation for this class was generated from the following file:
  • include/contur/cpu/alu.h