contur2
Loading...
Searching...
No Matches
contur::Cpu Class Referencefinal

Concrete CPU implementation. More...

#include <cpu.h>

Inheritance diagram for contur::Cpu:
Collaboration diagram for contur::Cpu:

Public Member Functions

 Cpu (IMemory &memory)
 Constructs a CPU connected to the given memory.
 ~Cpu () override
 Cpu (const Cpu &)=delete
Cpuoperator= (const Cpu &)=delete
 Cpu (Cpu &&) noexcept
Cpuoperator= (Cpu &&) noexcept
Interrupt step (RegisterFile &regs) override
 Performs a single fetch-decode-execute cycle.
void reset () noexcept override
 Resets the CPU's internal state (flags, etc.).
RegisterValue flags () const noexcept
 Returns the current comparison flags.
Public Member Functions inherited from contur::ICPU
virtual ~ICPU ()=default

Private Attributes

std::unique_ptr< Impl > impl_

Additional Inherited Members

Protected Member Functions inherited from contur::ICPU
 ICPU ()=default
 ICPU (const ICPU &)=default
ICPUoperator= (const ICPU &)=default
 ICPU (ICPU &&)=default
ICPUoperator= (ICPU &&)=default

Detailed Description

Concrete CPU implementation.

The CPU performs the fetch-decode-execute cycle:

  1. Fetch: read Block from memory at address pointed to by PC
  2. Decode: interpret the Block's fields (opcode, register, operand, state)
  3. Execute: perform the operation (ALU for arithmetic/logic, direct for control flow)

Instruction encoding in Block:

  • code — the Instruction opcode
  • reg — target (or source) register index
  • operand — immediate value, memory address, or second register index
  • state — addressing mode: 0 = immediate, 1 = register-register

Definition at line 29 of file cpu.h.

Constructor & Destructor Documentation

◆ Cpu() [1/3]

contur::Cpu::Cpu ( IMemory & memory)
explicit

Constructs a CPU connected to the given memory.

Parameters
memoryReference to the memory subsystem (must outlive the CPU).

◆ ~Cpu()

contur::Cpu::~Cpu ( )
override

◆ Cpu() [2/3]

contur::Cpu::Cpu ( const Cpu & )
delete

◆ Cpu() [3/3]

contur::Cpu::Cpu ( Cpu && )
noexcept

Member Function Documentation

◆ flags()

RegisterValue contur::Cpu::flags ( ) const
nodiscardnoexcept

Returns the current comparison flags.

Flags are set by the Compare instruction:

  • Bit 0 (ZERO_FLAG): set if operands were equal
  • Bit 1 (SIGN_FLAG): set if first operand was less than second

◆ operator=() [1/2]

Cpu & contur::Cpu::operator= ( const Cpu & )
delete

◆ operator=() [2/2]

Cpu & contur::Cpu::operator= ( Cpu && )
noexcept

◆ reset()

void contur::Cpu::reset ( )
overridevirtualnoexcept

Resets the CPU's internal state (flags, etc.).

Implements contur::ICPU.

◆ step()

Interrupt contur::Cpu::step ( RegisterFile & regs)
nodiscardoverridevirtual

Performs a single fetch-decode-execute cycle.

Reads the instruction at the address given by the Program Counter in regs, decodes it, executes it (updating regs and possibly memory), and advances the PC.

Parameters
regsThe register file for the currently running process.
Returns
An Interrupt code indicating the result:

Implements contur::ICPU.

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::Cpu::impl_
private

Definition at line 59 of file cpu.h.


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