P5: Ripple Carry Adder/Subtracter

Published

February 27, 2026

Due
March 04, 2026 at 11:59 PM

Goals

  • Demonstrate your knowledge of basic circuit design
  • Put your knowledge about two’s compliment numbers to use

Objective

The goal of this problem is to build a 4-bit two’s compliment adder/subtracter.

The circuit will take in two 4-bit two’s compliment numbers and a control line. It will either add the two numbers or subtract the second from the first based on the value of the control line.

Requirements

  • your work must be in a file called ripple_carry_adder.circ
  • your implementation must be in the main circuit (you are welcome to create sub-circuits however)
  • your circuit must have three inputs: A, B and sub.
  • A and B are both 4-bit values and are the numeric inputs to the circuit
  • sub is 1-bit – when it is 0, compute A + B, when it is 1, compute A - B.
  • your circuit must have two outputs: result and ovf
  • result is a 4-bit value that is either A+B or A-B depending on the state of sub
  • ovf indicates if the operation resulted in overflow or underflow (it will be 0 if the computation is correct, and 1 otherwise)
  • you are restricted to
    • input pins
    • output pins
    • splitters
    • components in the Gates library (i.e., basic logic gates)
  • you must include a text vector in a file called adder-test.txt

Test vector

For this circuit I would like you to write a test vector file for the circuit and include it in your submission.

We now have a circuit with nine bits of input, which gives us \(2^{9} = 512\) rows in our truth table, which may be more than you are ready to write out.

You could write a program to generate all of the possibilities, but I won’t ask that of you.

Instead, I invite you to contemplate a smaller set of tests that would cover the functionality of the circuit without having to enumerate every possibility. When selecting these, think about the circuit and where things might be a problem if they are hooked up improperly. Edge cases in the data are also frequent source of errors.

The other thing to be aware of is that we need to change the file a little bit when we are working with multi-bit inputs and outputs.

To label a pin has being multi-bit in the test file, add a square bracket with the bit width inside after the name of the variable.

For the rows, you can represent the multi-values as a set of 1s and 0s or you can write the value in hex, remembering to preface hex numbers with 0x.

Example:

A[4] B[4] sub ovf result

0110 0001 0 0 0111
0x6 0x1 1 0 0x5

Implementation

This is a step up in complexity from our previous circuits. Here are some tips for you:

  • recall that we can add two two’s compliment numbers together regardless of whether or not either one is positive or negative

  • recall that our only concession to two’s compliment is that overflow detection has a little more complexity

  • recall that subtracting a number is the same as adding the inverse

  • recall that we negate a number by flipping all of the bits and adding 1

Submission

Upload your .circ file and test vector to Gradescope.