def test_or_multiway(self): "Checks that or_multiway returns 1 if any bits in the number = 1, and 0 only if all bits = 0" self.assertTrue(or_multiway(m_eight)) self.assertTrue(or_multiway(neg_three)) self.assertTrue(or_multiway(m_one)) self.assertTrue(or_multiway(neg_one)) self.assertFalse(or_multiway(m_zero))
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)
def test_or_multiway(self): self.assertTrue(str(or_multiway(m_eight))) self.assertTrue(str(or_multiway(m_fifteen))) self.assertTrue(str(or_multiway(m_one))) self.assertTrue(str(or_multiway(m_zero)))