/* Renata Lara */ /* Computer Architecture */ /* Dr. Abraham */ /* February 22, 1999 */ /* This program performs a full adder operation. */ /* Class1.java initializes an object of type HalfAdder */ /* which performs the basic ANDgate, ORgate, and */ /* NOTgate functions. HalfAdder is utilized twice. */ import java.io.*; public class Class1 { public static void main (String[] args)throws IOException { HalfAdder ha; int[] A = new int[2], B = new int[2], C = new int[2]; int[] total = new int[3]; int bitA, bitB, carrybit=0, carrybit1, carrybit2; int sum=0, carry=0; String answer; InputStreamReader isr = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(isr); File outfile = new File("adder"); FileOutputStream fos = new FileOutputStream(outfile); PrintStream out = new PrintStream(fos); ha = new HalfAdder(); for(int x = 0; x<2; x++) { A[x] = ha.getA(x); B[x] = ha.getB(x); C[x] = ha.getC(x); //solves the first half adder, which returns the sum and carry carry = ha.ORgate(A[x], carry); bitA = ha.ORgate(carry, B[x]); bitB = ha.ANDgate(A[x], B[x]); carrybit1 = bitB; bitB = ha.NOTgate(bitB); sum = ha.ANDgate(bitA, bitB); //solves the second half adder to finalize the full adder B[x] = sum; bitA = ha.ORgate(B[x], C[x]); bitB = ha.ANDgate(B[x], C[x]); carrybit2 = bitB; bitB = ha.NOTgate(bitB); sum = ha.ANDgate(bitA, bitB); //the result for sum and carrybit carrybit = ha.ORgate(carrybit1, carrybit2); total[x] = sum; carry = carrybit; } total[0] = carry; System.out.println("SUM: "); for (int b = 0; b<2; b++) { System.out.print(total[b]); } System.out.println(); System.out.println("CARRY: " + total[2]); answer = in.readLine(); System.out.flush(); System.out.println(); }//end of main }//end of class Class1