class BaseGeneralPurposeRegister(BaseDataRegister): """ This class represents a register that holds a value with no specific context. Each register has an input component, whose value is transferred to the register (if write is enabled). """ def __init__(self, register_id, register_name, size): super().__init__(register_id, register_name) self._content = BitValue(bits=size) @property def content(self): return self._content.value @content.setter def content(self, value): self._content.value = value def __len__(self): return len(self._content) def __getitem__(self, item): return self._content[item] def clear(self): self._buffer.value = 0 def increment(self): self._buffer = self._content.copy() self._buffer.increment() def __bool__(self): return bool(self._content) def __int__(self): return int(self._content) int = __int__ __index__ = __int__ def bin(self): return self._content.bin() __str__ = bin def oct(self): return self._content.oct() def dec(self): return self._content.dec() def hex(self): return self._content.hex()
class FlagRegister(DataComponent): """ This class represents a register that holds the values of a set of one-bit flags. Each flag can be set or cleared separately, but some actions can be taken on the register as a whole. Not all bits in a flag register need to be assigned to working flags. Flags can be accessed by index, or by name. """ def __init__(self, register_id, register_name, size): super().__init__(register_id, register_name) self._content = BitValue(bits=size) @property def content(self): return self._content.value @content.setter def content(self, value): self._content.value = value def __len__(self): return len(self._content) def __getitem__(self, item): return self._content[item] def up_tick(self): # TODO: implement this raise NotImplementedError def down_tick(self): # TODO: implement this raise NotImplementedError def __int__(self): return int(self._content) int = __int__ __index__ = __int__ def bin(self): return self._content.bin() __str__ = bin def oct(self): return self._content.oct() def dec(self): return self._content.dec() def hex(self): return self._content.hex()
def hex(self): return BitValue(self.bin(), len(self)).hex()
def dec(self): return BitValue(self.bin(), len(self)).dec()
def oct(self): return BitValue(self.bin(), len(self)).oct()
def __int__(self): return int(BitValue(self.bin(), len(self)))
def increment(self): bv = BitValue(self.bin(), len(self)) bv.increment() self.content = bv
def __getitem__(self, item): bv = BitValue(self.bin(), len(self)) return bv[item]
def content(self, value): start, end, length = self._slice before, after = self._parent[:start], self._parent[end:] content = "0b" + after + BitValue(value, length).value + before self._parent.content = content
def __init__(self, register_id, register_name, size): super().__init__(register_id, register_name) self._content = BitValue(bits=size)