// // Adder.C // // Description: // A simple adder object used for addition only // // Version: // $Id$ // // Revision: // $Log$ // // Author: // Brian J. Alliet // Jonathon W. Donaldson // #include "includes.h" Adder::Adder(const char *id, int numbits) : CPUObject(id,numbits), // superclass Connector(id,numbits), // superclass m_output(id,numbits,*this), // initialize outflow m_op1(0), m_op2(0) { } Adder::~Adder() { } /* * Fetches the operand values */ void Adder::connectFrom(OutFlow &op1, OutFlow &op2) { if(Clock::getTime()) { throw ArchLibError("Adder connection attempted after start of simulation"); } m_op1 = &op1; m_op2 = &op2; } /* * Compute value in the adder */ long Adder::computeValue() { bool trace = CPUObject::debug & CPUObject::trace; // if either operand is not connected then BLOW-UP! if(!m_op1 || !m_op2) { throw ArchLibError("Adder not connected to two operands"); } if(trace) { cout << "("; } long op1 = m_op1->fetchValue(); if(trace) { cout << ") + ("; } long op2 = m_op2->fetchValue(); if(trace) { cout << ") "; } // and'ing with mask removes any bits larger than the bus size return (op1 + op2) & get_mask(); }