Arithmetic

Adder4

Class bw.arithmetic.Adder4

_images/Adder4.svg

Defined in bitwise/arithmetic/ADD.py.

4-bit adder.

__init__

__init__(
    carry_in,
    a_bus,
    b_bus,
    carry_out,
    sum_bus
)

Construct a new 4-bit adder.

Args:

  • carry_in: An object of type Wire. The carry-in to the adder.
  • a_bus: An object of type Bus4. The first addend. a_bus[0] and a_bus[3] are the most and least significant bit, respectively.
  • b_bus: An object of type Bus4. The second addend. b_bus[0] and b_bus[3] are the most and least significant bit, respectively.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus4. The sum of the two addends. sum_bus[0] and sum_bus[3] are the most and least significant bit, respectively.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 4.

__str__

Print out the wire values of the 4-bit adder.

carry_in: 0
a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0)

__call__

__call__(
    carry_in=None,
    a_bus=None,
    b_bus=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 4-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

Adder8

Class bw.arithmetic.Adder8

_images/Adder8.svg

Defined in bitwise/arithmetic/ADD.py.

8-bit adder.

__init__

__init__(
    carry_in,
    a_bus,
    b_bus,
    carry_out,
    sum_bus
)

Construct a new 8-bit adder.

Args:

  • carry_in: An object of type Wire. The carry-in to the adder.
  • a_bus: An object of type Bus8. The first addend. a_bus[0] and a_bus[7] are the most and least significant bit, respectively.
  • b_bus: An object of type Bus8. The second addend. b_bus[0] and b_bus[7] are the most and least significant bit, respectively.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus8. The sum of the two addends. sum_bus[0] and sum_bus[7] are the most and least significant bit, respectively.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 8.

__str__

Print out the wire values of the 8-bit adder.

carry_in: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    carry_in=None,
    a_bus=None,
    b_bus=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 8-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

Adder16

Class bw.arithmetic.Adder16

_images/Adder16.svg

Defined in bitwise/arithmetic/ADD.py.

16-bit adder.

__init__

__init__(
    carry_in,
    a_bus,
    b_bus,
    carry_out,
    sum_bus
)

Construct a new 16-bit adder.

Args:

  • carry_in: An object of type Wire. The carry-in to the adder.
  • a_bus: An object of type Bus16. The first addend. a_bus[0] and a_bus[15] are the most and least significant bit, respectively.
  • b_bus: An object of type Bus16. The second addend. b_bus[0] and b_bus[15] are the most and least significant bit, respectively.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus16. The sum of the two addends. sum_bus[0] and sum_bus[15] are the most and least significant bit, respectively.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 16.

__str__

Print out the wire values of the 16-bit adder.

carry_in: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    carry_in=None,
    a_bus=None,
    b_bus=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 16-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

AdderSubtractor4

Class bw.arithmetic.AdderSubtractor4

_images/AdderSubtractor4.svg

Defined in bitwise/arithmetic/ADD_SUB.py.

4-bit adder-subtractor.

__init__

__init__(
    add_subtract,
    a_bus,
    b_bus,
    overflow,
    carry_out,
    sum_bus
)

Construct a new 4-bit adder-subtractor.

Args:

  • add_subtract: An object of type Wire. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
  • a_bus: An object of type Bus4. The first addend, or the minuend. a_bus[0] and a_bus[3] are the most and least significant bit, respectively. a_bus[0] is the sign bit in subtraction operations.
  • b_bus: An object of type Bus4. The second addend, or the subtrahend. b_bus[0] and b_bus[3] are the most and least significant bit, respectively. b_bus[0] is the sign bit in subtraction operations.
  • overflow: An object of type Wire. The overflow indicator of the subtractor.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus4. The sum of the two addends, or the difference between the minuend and the subtrahend. sum_bus[0] and sum_bus[3] are the most and least significant bit, respectively. sum_bus[0] is the sign bit in subtraction operations.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 4.

__str__

Print out the wire values of the 4-bit adder-subtractor.

add_subtract: 0
a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0)

__call__

__call__(
    add_subtract=None,
    a_bus=None,
    b_bus=None,
    overflow=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 4-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

AdderSubtractor8

Class bw.arithmetic.AdderSubtractor8

_images/AdderSubtractor8.svg

Defined in bitwise/arithmetic/ADD_SUB.py.

8-bit adder-subtractor.

__init__

__init__(
    add_subtract,
    a_bus,
    b_bus,
    overflow,
    carry_out,
    sum_bus
)

Construct a new 8-bit adder-subtractor.

Args:

  • add_subtract: An object of type Wire. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
  • a_bus: An object of type Bus8. The first addend, or the minuend. a_bus[0] and a_bus[7] are the most and least significant bit, respectively. a_bus[0] is the sign bit in subtraction operations.
  • b_bus: An object of type Bus8. The second addend, or the subtrahend. b_bus[0] and b_bus[7] are the most and least significant bit, respectively. b_bus[0] is the sign bit in subtraction operations.
  • overflow: An object of type Wire. The overflow indicator of the subtractor.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus8. The sum of the two addends, or the difference between the minuend and the subtrahend. sum_bus[0] and sum_bus[7] are the most and least significant bit, respectively. sum_bus[0] is the sign bit in subtraction operations.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 8.

__str__

Print out the wire values of the 8-bit adder-subtractor.

add_subtract: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    add_subtract=None,
    a_bus=None,
    b_bus=None,
    overflow=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 8-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

AdderSubtractor16

Class bw.arithmetic.AdderSubtractor16

_images/AdderSubtractor16.svg

Defined in bitwise/arithmetic/ADD_SUB.py.

16-bit adder-subtractor.

__init__

__init__(
    add_subtract,
    a_bus,
    b_bus,
    overflow,
    carry_out,
    sum_bus
)

Construct a new 16-bit adder-subtractor.

Args:

  • add_subtract: An object of type Wire. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
  • a_bus: An object of type Bus16. The first addend, or the minuend. a_bus[0] and a_bus[15] are the most and least significant bit, respectively. a_bus[0] is the sign bit in subtraction operations.
  • b_bus: An object of type Bus16. The second addend, or the subtrahend. b_bus[0] and b_bus[15] are the most and least significant bit, respectively. b_bus[0] is the sign bit in subtraction operations.
  • overflow: An object of type Wire. The overflow indicator of the subtractor.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum_bus: An object of type Bus16. The sum of the two addends, or the difference between the minuend and the subtrahend. sum_bus[0] and sum_bus[15] are the most and least significant bit, respectively. sum_bus[0] is the sign bit in subtraction operations.

Raises:

  • TypeError: If either a_bus, b_bus, or sum_bus is not a bus of width 16.

__str__

Print out the wire values of the 16-bit adder-subtractor.

add_subtract: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    add_subtract=None,
    a_bus=None,
    b_bus=None,
    overflow=None,
    carry_out=None,
    sum_bus=None
)

Force specific values on the wires of the 16-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

FullAdder

Class bw.arithmetic.FullAdder

_images/FullAdder.svg

Defined in bitwise/arithmetic/ADD.py.

Full adder.

__init__

__init__(
    carry_in,
    a,
    b,
    carry_out,
    sum
)

Construct a new full adder.

Args:

  • carry_in: An object of type Wire. The carry-in to the adder.
  • a: An object of type Wire. The first addend.
  • b: An object of type Wire. The second addend.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum: An object of type Wire. The sum of the two addends.

__str__

Print out the wire values of the full adder.

carry_in: 0
a: 0
b: 0
carry_out: 0
sum: 0

__call__

__call__(
    carry_in=None,
    a=None,
    b=None,
    carry_out=None,
    sum=None
)

Force specific values on the wires of the full adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

HalfAdder

Class bw.arithmetic.HalfAdder

_images/HalfAdder.svg

Defined in bitwise/arithmetic/ADD.py.

Half adder.

__init__

__init__(
    a,
    b,
    carry_out,
    sum
)

Construct a new half adder.

Args:

  • a: An object of type Wire. The first addend.
  • b: An object of type Wire. The second addend.
  • carry_out: An object of type Wire. The carry-out of the adder.
  • sum: An object of type Wire. The sum of the two addends.

__str__

Print out the wire values of the half adder.

a: 0
b: 0
carry_out: 0
sum: 0

__call__

__call__(
    a=None,
    b=None,
    carry_out=None,
    sum=None
)

Force specific values on the wires of the half adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

Multiplier2

Class bw.arithmetic.Multiplier2

_images/Multiplier2.svg

Defined in bitwise/arithmetic/MULT.py.

2-bit unsigned array multiplier.

__init__

__init__(
    a_1,
    a_2,
    b_1,
    b_2,
    product_bus
)

Construct a new 2-bit unsigned multiplier.

Args:

  • a_1: An object of type Wire. The most significant bit of the multiplicand.
  • a_2: An object of type Wire. The least significant bit of the multiplicand.
  • b_1: An object of type Wire. The most significant bit of the multiplier.
  • b_2: An object of type Wire. The least significant bit of the multiplier.
  • product_bus: An object of type Bus4. The product. product_bus[0] and product_bus[3] are the most and least significant bit, respectively.

Raises:

  • TypeError: If product_bus is not a bus of width 4.

__str__

Print out the wire values of the 2-bit unsigned multiplier.

a_1: 0
a_2: 0
b_1: 0
b_2: 0
product_bus: (0, 0, 0, 0)

__call__

__call__(
    a_1=None,
    a_2=None,
    b_1=None,
    b_2=None,
    product_bus=None
)

Force specific values on the wires of the 2-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

Multiplier4

Class bw.arithmetic.Multiplier4

_images/Multiplier4.svg

Defined in bitwise/arithmetic/MULT.py.

4-bit unsigned array multiplier.

__init__

__init__(
    a_bus,
    b_bus,
    product_bus
)

Construct a new 4-bit unsigned multiplier.

Args:

  • a_bus: An object of type Bus4. The multiplicand. a_bus[0] and a_bus[3] are the most and least significant bit, respectively.
  • b_bus: An object of type Bus4. The multiplier. b_bus[0] and b_bus[3] are the most and least significant bit, respectively.
  • product_bus: An object of type Bus8. The product. product_bus[0] and product_bus[7] are the most and least significant bit, respectively.

Raises:

  • TypeError: If either a_bus or b_bus is not a bus of width 4, or if product_bus is not a bus of width 8.

__str__

Print out the wire values of the 4-bit unsigned multiplier.

a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
product_bus: (0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    a_bus=None,
    b_bus=None,
    product_bus=None
)

Force specific values on the wires of the 4-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

Multiplier8

Class bw.arithmetic.Multiplier8

_images/Multiplier8.svg

Defined in bitwise/arithmetic/MULT.py.

8-bit unsigned array multiplier.

__init__

__init__(
    a_bus,
    b_bus,
    product_bus
)

Construct a new 8-bit unsigned multiplier.

Args:

  • a_bus: An object of type Bus8. The multiplicand. a_bus[0] and a_bus[7] are the most and least significant bit, respectively.
  • b_bus: An object of type Bus8. The multiplier. b_bus[0] and b_bus[7] are the most and least significant bit, respectively.
  • product_bus: An object of type Bus16. The product. product_bus[0] and product_bus[15] are the most and least significant bit, respectively.

Raises:

  • TypeError: If either a_bus or b_bus is not a bus of width 8, or if product_bus is not a bus of width 16.

__str__

Print out the wire values of the 16-bit unsigned multiplier.

a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
product_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

__call__

__call__(
    a_bus=None,
    b_bus=None,
    product_bus=None
)

Force specific values on the wires of the 16-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.