示例#1
0
def sub(clock, write, address, data_in):
    assert len(address) >= 2
    address = address[:2]

    control_lines = address_decode(address)

    write_a = And(clock, write, control_lines[0])
    a = register(data_in, write_a)

    write_b = And(clock, write, control_lines[1])
    b = register(data_in, write_b)

    res, carry = ripple_subtractor(a, b)
    carry = pad([carry], len(data_in))

    return word_switch(control_lines, a, b, res, carry)
示例#2
0
def test_ripple_subtractor():
    network = core.Network()
    a = test_utils.BinaryIn(network, 8)
    b = test_utils.BinaryIn(network, 8)
    r, c = adders.ripple_subtractor(a, b)
    r = test_utils.BinaryOut(r)

    for i in range(10):
        v1 = random.randrange(256)
        v2 = random.randrange(256)
        print v1, v2
        a.write(v1)
        b.write(v2)
        network.drain()
        assert c.read() == (v1 < v2)
        assert r.read() == (v1 - v2) % 256
示例#3
0
def test_ripple_subtractor():
    network = core.Network()
    a = test_utils.BinaryIn(network, 8)
    b = test_utils.BinaryIn(network, 8)
    r, c = adders.ripple_subtractor(a, b)
    r = test_utils.BinaryOut(r)

    for i in range(10):
        v1 = random.randrange(256)
        v2 = random.randrange(256)
        print(v1, v2)
        a.write(v1)
        b.write(v2)
        network.drain()
        assert c.read() == (v1 < v2)
        assert r.read() == (v1 - v2) % 256