예제 #1
0
def tabulate(in_wires, out_wires):
    sim = logsim.Sim()
    for values in truth_table(in_wires):
        for wire, value in zip(in_wires, values):
            sim.initialize(wire, value)
        sim.ticktock()
        print ' '.join(map(str,
                           wire_values(in_wires) + wire_values(out_wires)))


def wire_values(wires):
    return tuple(wire.value for wire in wires)


def truth_table(wires):
    return product(*[(0, 1)] * len(wires))


if __name__ == '__main__':
    a = logsim.Wire()
    b = logsim.Wire()
    tabulate([a, b], [logsim.nand(a, b)])
    print ''
    tabulate([a, b], [a & b])
    print ''
    tabulate([a, b], [a | b])
    print ''
    tabulate([a, b], [a ^ b])
    print ''
예제 #2
0
파일: gates.py 프로젝트: fuath/logsim
def xor(a, b):
    return nand(nand(a, ~b),
                nand(~a, b))
예제 #3
0
파일: gates.py 프로젝트: fuath/logsim
def or_(a, b):
    return nand(~a, ~b)
예제 #4
0
파일: gates.py 프로젝트: fuath/logsim
def and_(a, b):
    return ~nand(a, b)
예제 #5
0
파일: gates.py 프로젝트: fuath/logsim
def not_(a):
    return nand(a, a)
예제 #6
0
파일: tabulate.py 프로젝트: darius/logsim
from itertools import product

import logsim

def tabulate(in_wires, out_wires):
    sim = logsim.Sim()
    for values in truth_table(in_wires):
        for wire, value in zip(in_wires, values):
            sim.initialize(wire, value)
        sim.ticktock()
        print ' '.join(map(str, wire_values(in_wires) + wire_values(out_wires)))

def wire_values(wires):
    return tuple(wire.value for wire in wires)

def truth_table(wires):
    return product(*[(0, 1)]*len(wires))


if __name__ == '__main__':
    a = logsim.Wire()
    b = logsim.Wire()
    tabulate([a, b], [logsim.nand(a, b)])
    print ''
    tabulate([a, b], [a & b])
    print ''
    tabulate([a, b], [a | b])
    print ''
    tabulate([a, b], [a ^ b])
    print ''