コード例 #1
0
ファイル: memory.py プロジェクト: paweusz/cpu
    def __init__(self):
        self.write = None
        self.enable = None
        self.clk = None
        self.d = [None] * Memory.WORD_SIZE
        self.o = [None] * Memory.WORD_SIZE
        self.a = [None] * Memory.ADDR_SIZE

        self.__words = [WideRegister(Memory.WORD_SIZE) for _ in range(Memory.MEM_SIZE)]
        self.__decoder = Decoder4By16()
        self.__enable_ands = [AndGate() for _ in range(Memory.MEM_SIZE)]
        self.__write_ands = [AndGate() for _ in range(Memory.MEM_SIZE)]
コード例 #2
0
    def __init__(self):
        self.xor1 = XorGate()
        self.xor2 = XorGate()
        self.and1 = AndGate()
        self.and2 = AndGate()
        self.or_gate = OrGate()

        self.a = None
        self.b = None
        self.cin = None

        self.s = None
        self.cout = None
コード例 #3
0
ファイル: registers.py プロジェクト: paweusz/cpu
    def __init__(self):
        self.load = None
        self.clk = None
        self.d = None
        self.q = None
        self.enable = None

        self.__not_gate = NotGate()
        self.__and_gate1 = AndGate()
        self.__and_gate2 = AndGate()
        self.__or_gate = OrGate()
        self.__d_latch = DLatch()
        self.__three_state = ThreeState()
コード例 #4
0
ファイル: subtractors.py プロジェクト: paweusz/cpu
    def __init__(self):
        self.x = None
        self.y = None
        self.bin = None

        self.d = None
        self.bout = None

        self.__xor1 = XorGate()
        self.__xor2 = XorGate()
        self.__and1 = AndGate()
        self.__and2 = AndGate()
        self.__or1 = OrGate()
        self.__not2 = NotGate()
        self.__not3 = NotGate()
コード例 #5
0
ファイル: subtractors.py プロジェクト: paweusz/cpu
class FullSubtractor:
    def __init__(self):
        self.x = None
        self.y = None
        self.bin = None

        self.d = None
        self.bout = None

        self.__xor1 = XorGate()
        self.__xor2 = XorGate()
        self.__and1 = AndGate()
        self.__and2 = AndGate()
        self.__or1 = OrGate()
        self.__not2 = NotGate()
        self.__not3 = NotGate()

    def eval(self):
        self.__xor1.a = self.x
        self.__xor1.b = self.y
        self.__xor1.eval()

        self.__xor2.a = self.__xor1.q
        self.__xor2.b = self.bin
        self.__xor2.eval()

        self.__not2.a = self.x
        self.__not2.eval()

        self.__and1.a = self.__not2.q
        self.__and1.b = self.y
        self.__and1.eval()

        self.__not3.a = self.__xor1.q
        self.__not3.eval()

        self.__and2.a = self.bin
        self.__and2.b = self.__not3.q
        self.__and2.eval()

        self.__or1.a = self.__and1.q
        self.__or1.b = self.__and2.q
        self.__or1.eval()

        self.d = self.__xor2.q
        self.bout = self.__or1.q
コード例 #6
0
    def __init__(self):
        self.a = None
        self.b = None

        self.d0 = None
        self.d1 = None
        self.d2 = None
        self.d3 = None

        self.__nots = [NotGate() for _ in range(2)]
        self.__ands = [AndGate() for _ in range(4)]
コード例 #7
0
class FullAdder:

    def __init__(self):
        self.xor1 = XorGate()
        self.xor2 = XorGate()
        self.and1 = AndGate()
        self.and2 = AndGate()
        self.or_gate = OrGate()

        self.a = None
        self.b = None
        self.cin = None

        self.s = None
        self.cout = None

    def eval(self):
        self.xor1.a = self.a
        self.xor1.b = self.b
        self.xor1.eval()
        
        self.xor2.a = self.xor1.q
        self.xor2.b = self.cin
        self.xor2.eval()

        self.s = self.xor2.q

        self.and1.a = self.xor1.q
        self.and1.b = self.cin
        self.and1.eval()

        self.and2.a = self.a
        self.and2.b = self.b
        self.and2.eval()

        self.or_gate.a = self.and1.q
        self.or_gate.b = self.and2.q
        self.or_gate.eval()

        self.cout = self.or_gate.q
コード例 #8
0
ファイル: registers.py プロジェクト: paweusz/cpu
class Register:
    def __init__(self):
        self.load = None
        self.clk = None
        self.d = None
        self.q = None
        self.enable = None

        self.__not_gate = NotGate()
        self.__and_gate1 = AndGate()
        self.__and_gate2 = AndGate()
        self.__or_gate = OrGate()
        self.__d_latch = DLatch()
        self.__three_state = ThreeState()

    def eval(self):
        self.__not_gate.a = self.load
        self.__not_gate.eval()

        self.__and_gate1.a = self.__d_latch.q
        self.__and_gate1.b = self.__not_gate.q
        self.__and_gate1.eval()

        self.__and_gate2.a = self.load
        self.__and_gate2.b = self.d
        self.__and_gate2.eval()

        self.__or_gate.a = self.__and_gate1.q
        self.__or_gate.b = self.__and_gate2.q
        self.__or_gate.eval()

        self.__d_latch.d = self.__or_gate.q
        self.__d_latch.e = self.clk
        self.__d_latch.eval()

        self.__three_state.a = self.__d_latch.q
        self.__three_state.b = self.enable
        self.__three_state.eval()

        self.q = self.__three_state.c
コード例 #9
0
    def __init__(self):
        self.enable = None

        self.a = None
        self.b = None

        self.d0 = None
        self.d1 = None
        self.d2 = None
        self.d3 = None

        self.__decoder_2_by_4 = Decoder2By4()
        self.__enable_ands = [AndGate() for _ in range(4)]
コード例 #10
0
    def __init__(self):
        self.clk = None
        self.out = [None for _ in range(Counter.REG_WIDTH)]

        self.__flip_flops = [JKFlipFlop() for _ in range(Counter.REG_WIDTH)]
        self.__and_gates = [AndGate() for _ in range(Counter.REG_WIDTH - 2)]