def ripple(a: List[bool], b: List[bool], cin: bool = False, invert_b: bool = False) -> List[bool]:
# allocate result bits
result = list(range(0, Memory.REGISTER_WIDTH)) # type: List[bool]
carry_wire = cin # type: bool
# go backwards to preserve carry propagation
for i in range(max(len(a), len(b)) - 1, -1, -1):
# sign extend, should not be needed as long as the memory row has all 8 bits filled out
# if i < 8 - len(a):
# a_bit = a[0]
# b_bit = b[i]
# elif i < 8 - len(b):
# a_bit = a[i]
# b_bit = b[0]
# else:
a_bit = a[i]
b_bit = b[i]
if invert_b:
b_bit = not b_bit
result[i], carry_wire = full_adder(carry_wire, a_bit, b_bit)
return result
评论列表
文章目录