P5: Ripple Carry Adder/Subtracter
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
maincircuit (you are welcome to create sub-circuits however) - your circuit must have three inputs:
A,Bandsub. AandBare both 4-bit values and are the numeric inputs to the circuitsubis 1-bit – when it is 0, computeA + B, when it is 1, computeA - B.- your circuit must have two outputs:
resultandovf resultis a 4-bit value that is eitherA+BorA-Bdepending on the state ofsubovfindicates 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.