Question: Task 3 : Build a signed adder Implement a 1 6 - bit signed adder using any algorithm you wish, provided the circuit has a

Task 3: Build a signed adder
Implement a 16-bit signed adder using any algorithm you wish, provided the circuit has a reasonable running time and size. Faster adders will receive more points. (See Grading section below.) Your adder must report overflow conditions when they occur (with respect to signed inputs). This circuit must have an input named CarryIn. You will use this input for future projects.
Your inputs must be named InputA, InputB, and CarryIn. Your circuit will not work with my tests otherwise.
Your outputs must be named Output, CarryOut, and Overflow. CarryOut is the carry out from the last full adder. It is also, in effect, the overflow indicator for unsigned inputs. Overflow is the overflow indicator for signed inputs. CarryOut and Overflow will not necessarily have the same value.
You may use SampleSigned16BitAdderTest as a basis for your own tests. A word of warning: these tests scripts are incomplete. Don't assume that a circuit passing these sample tests will pass all of my tests. Add test cases to ensure correct functionality.
Rules:
The simulator comes with a built-in adder. You may not use the built-in adder.
To build the required circuits, you will probably find it useful to design and build several subcircuits. These subcircuits may have any interface you choose; however, you are responsible for testing them.
You must write all of your own chips. Do not share "internal" chips with your classmates or download them off the Internet.
Be sure to test your components thoroughly. Just because it passes the included tests does not mean it will pass mine. test your adder yourself using DLUnit.
SampleSigned16BitAdderTest
import org.junit.Assert;
import org.junit.Test;
import static edu.gvsu.dlunit.DLUnit.*;
/**
* Sample test cases for an signed, 16-bit adder with a carry-in and overflow.
* IMPORTANT: These test cases do *not* thoroughly test the adder. You need to
* re-name this class and add more tests!
*/
public class SampleSigned16BitAdderTest {
// The complete list of integers to be tests.
//(IMPORTANT !!! You need to add to this list !!!)
public static final long testIntegers[]={-32768,-32767,0,1,2,13,127,128,129,0x5555,32766,32767};
// Helper method that runs a test for a given pair of integers and a carryIn.
protected static void verify(long a, long b, boolean carryIn){
//////////////////////////////////
//
// Compute the expected outputs
//
/////////////////////////////////
long carryInAsInt =(carryIn ?1 : 0); // convert the Boolean to 0 or 1
long expected = a + b + carryInAsInt; // expected output value
// The `overflow` output should be `true` if the expected output is not in the
// range [-(2^15),(2^15)-1]
//(In java "1<<15" takes the bit string 0000000000000001 and shifts it left
//15 spaces, effectively
// generating the value 2^15.)
boolean expectedOverflow =((expected >=(1<<15))||(expected <-(1<<15)));
// Output "wraps around" if there is an overflow
if (expectedOverflow && expected >0){
expected -=65536;
} else if (expectedOverflow && expected <0){
expected +=65536;
}
////////////////////////////////////////
//
// Configure and simulate the circuit
//
///////////////////////////////////////
setPinSigned("InputA", a);
setPinSigned("InputB", b);
setPin("CarryIn", carryIn);
run();
////////////////////////////////////////
//
// Check the correctness of the output
//
///////////////////////////////////////
String message ="of "+ a +"+"+ b +" with "+(carryIn ?"a " : " no ")+" carry in";
Assert.assertEquals("Output "+ message, expected, readPinSigned("Output"));
Assert.assertEquals("Overflow "+ message, expectedOverflow, readPin("Overflow"));
}
//
// Quick tests designed to quickly catch major errors. (Also serve as example
// tests)
//
@Test
public void zero_zero_false(){
verify(0,0, false);
}
@Test
public void zero_one_false(){
verify(0,1, false);
}
@Test
public void zero_zero_true(){
verify(0,0, true);
}
@Test
public void zero_one_true(){
verify(0,1, true);
}
// This is actually rather gross; but, it is an effective way to thoroughly test
// your adder without
// having to write hundreds of individual methods.
@Test
public void testAll(){
for (long a : testIntegers){
for (long b : testIntegers){
verify(a, b, false);
verify(a, b, true);
}
}
}// end testAll
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!