operations.py 文件源码

python
阅读 55 收藏 0 点赞 0 评论 0

项目:PicoSim 作者: Vadman97 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号