Ejemplo n.º 1
0
    def test_multimux(self):

        zero3 = Multi([zero, zero, zero])

        self.assertEquals(str(multimux(m_eight, m_zero, zero)), str(m_eight))
        self.assertEquals(str(multimux(m_eight, m_fifteen, one)), str(m_fifteen))
        self.assertEquals(str(multimux(m_zero, m_one, zero)), str(zero3))
        self.assertEquals(str(multimux(m_zero, m_one, one)), str(m_one))
Ejemplo n.º 2
0
    def test_multimux(self):

        zero3 = Multi([zero, zero, zero])

        self.assertEquals(str(multimux(m_eight, m_zero, zero)), str(m_eight))
        self.assertEquals(str(multimux(m_eight, m_fifteen, one)),
                          str(m_fifteen))
        self.assertEquals(str(multimux(m_zero, m_one, zero)), str(zero3))
        self.assertEquals(str(multimux(m_zero, m_one, one)), str(m_one))
Ejemplo n.º 3
0
    def __call__(self, multi, load, increase, reset, clock):
        # if load, inc, or reset are set, load should be set for the register
        reg_load = load | increase | reset
        # if inc = 1, return (value + 1), else return value
        if_increase = multimux(self.value, inc(self.value), increase)
        # if load = 1, return multi, else return if_increase
        if_out = multimux(if_increase, multi, load)
        # if reset = 1, return 0, else return if_out
        if_reset = multimux(if_out, Multi(zero for i in range(16)), reset)

        self.value = self.reg(if_reset, reg_load, clock)
        return self.value
Ejemplo n.º 4
0
    def __call__(self, multi, load, increase, reset, clock):
        # if load, inc, or reset are set, load should be set for the register
        reg_load = load | increase | reset
        # if inc = 1, return (value + 1), else return value
        if_increase = multimux(self.value, inc(self.value), increase)
        # if load = 1, return multi, else return if_increase
        if_out = multimux(if_increase, multi, load)
        # if reset = 1, return 0, else return if_out
        if_reset = multimux(if_out, Multi(zero for i in range(16)), reset)

        self.value = self.reg(if_reset, reg_load, clock)
        return self.value
Ejemplo n.º 5
0
def alu(x, y, zx, nx, zy, ny, f, no):
    """Calculates a variety of functions on x and y, determined by the combination of control bits
        Outputs (out, zr, ng) where out is the 16-bit Multi result, and zr and ng are single Bits"""

    neg_one = Multi(Bit(digit) for digit in '1111111111111111')

    zero_x = x & Multi(~Bit(zx) for bit in range(16))
    zero_y = y & Multi(~Bit(zy) for bit in range(16))
    x2 = multimux(zero_x, ~zero_x, nx)
    y2 = multimux(zero_y, ~zero_y, ny)
    f_xy = multimux(x2 & y2, add_multi(x2, y2), f)
    out = multimux(f_xy, ~f_xy, no)
    zr = ~(or_multiway(out))
    ng = out[0]

    return (out, zr, ng)
Ejemplo n.º 6
0
def alu(x, y, zx, nx, zy, ny, f, no):
    """Calculates a variety of functions on x and y, determined by the combination of control bits
        Outputs (out, zr, ng) where out is the 16-bit Multi result, and zr and ng are single Bits"""
    
    neg_one = Multi(Bit(digit) for digit in '1111111111111111')

    zero_x = x & Multi(~Bit(zx) for bit in range(16))
    zero_y = y & Multi(~Bit(zy) for bit in range(16))
    x2 = multimux(zero_x, ~zero_x, nx)
    y2 = multimux(zero_y, ~zero_y, ny)
    f_xy = multimux(x2 & y2, add_multi(x2, y2), f)
    out = multimux(f_xy, ~f_xy, no)
    zr = ~(or_multiway(out))
    ng = out[0]

    return (out, zr, ng)
Ejemplo n.º 7
0
    def test_multimux(self):
        "Checks that multimux(a, b) -> a if sel = 0, and b if sel = 1"

        zero3 = Multi([zero, zero, zero])

        self.assertEquals(str(multimux(m_eight, m_zero, zero)), str(m_eight))
        self.assertEquals(str(multimux(m_eight, m_fifteen, one)), str(m_fifteen))
        self.assertEquals(str(multimux(m_zero, m_one, zero)), str(zero3))
        self.assertEquals(str(multimux(m_zero, m_one, one)), str(m_one))
        self.assertEquals(str(multimux(neg_one, m_zero, zero)), str(neg_one))
        self.assertEquals(str(multimux(m_eight, neg_two, one)), str(neg_two))
        self.assertEquals(str(multimux(m_zero, neg_one, zero)), str(zero16))
        self.assertEquals(str(multimux(neg_one, m_one, one)), str(one16))