Contur 2
Educational OS kernel simulator
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

Referenced by ALU(), ALU(), operator=(), and operator=().

◆ ~ALU()

contur::ALU::~ALU ( )
default

◆ ALU() [2/3]

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

References ALU().

◆ ALU() [3/3]

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

References ALU().

Member Function Documentation

◆ add()

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

Addition: a + b.

References add().

Referenced by add().

◆ bitwiseAnd()

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

Bitwise AND: a & b.

References bitwiseAnd().

Referenced by bitwiseAnd().

◆ bitwiseOr()

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

Bitwise OR: a | b.

References bitwiseOr().

Referenced by bitwiseOr().

◆ bitwiseXor()

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

Bitwise XOR: a ^ b.

References bitwiseXor().

Referenced by bitwiseXor().

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

References compare().

Referenced by compare().

◆ div()

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

Division: a / b.

Returns
DivisionByZero error if b == 0.

References div().

Referenced by div().

◆ mul()

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

Multiplication: a * b.

References mul().

Referenced by mul().

◆ operator=() [1/2]

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

References ALU().

◆ operator=() [2/2]

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

References ALU().

◆ shiftLeft()

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

Left shift: a << b.

References shiftLeft().

Referenced by shiftLeft().

◆ shiftRight()

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

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

References shiftRight().

Referenced by shiftRight().

◆ sub()

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

Subtraction: a - b.

References sub().

Referenced by sub().

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