int main() { int *nope; int sum, carry; printf("HALF ADDER:\n"); printf("a\tb\tsum\tcarry\n"); nope = half_adder(0,0); printf("0\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = half_adder(0,1); printf("0\t1\t%d \t%d \n",*(nope+0),*(nope+1)); nope = half_adder(1,0); printf("1\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = half_adder(1,1); printf("1\t1\t%d \t%d \n",*(nope+0),*(nope+1)); printf("\n\n"); printf("FULL ADDER:\n"); printf("a\tb\tc\tsum\tcarry\n"); nope = full_adder(0,0,0); printf("0\t0\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(0,0,1); printf("0\t0\t1\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(0,1,0); printf("0\t1\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(0,1,1); printf("0\t1\t1\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(1,0,0); printf("1\t0\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(1,0,1); printf("1\t0\t1\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(1,1,0); printf("1\t1\t0\t%d \t%d \n",*(nope+0),*(nope+1)); nope = full_adder(1,1,1); printf("1\t1\t1\t%d \t%d \n",*(nope+0),*(nope+1)); return 0; }
void bv_utilst::adder( bvt &sum, const bvt &op, literalt carry_in, literalt &carry_out) { assert(sum.size()==op.size()); carry_out=carry_in; for(std::size_t i=0; i<sum.size(); i++) { sum[i] = full_adder(sum[i], op[i], carry_out, carry_out); } }
void Adder::gate_add(int x, int x_inv) { int id = 0;//what actions will happen (0 + 0 == 0, 1 + 1 id == 3, 1 + 0 == id == 2, 0 + 1 == id == 1) for (int i = 0; i < m_width - 1; i++) { if (x & (1 << i)) { id = 2; } else { id = 0; } if (x_inv & (1 << i)) { id++; } full_adder(id, m_width + i, i, i + 1, 2 * m_width); } id = 0; if (x & (1 << (m_width - 1))) { id = 2; } if (x_inv & (1 << (m_width - 1))) { id++; }//perform last addition half_adder(id, 2 * m_width - 1, m_width - 1, 2 * m_width); }