Mano pdp8 InstructionWord.cc

From Minor Miracle Software
Revision as of 17:04, 13 June 2016 by WikiSysop (talk | contribs) (Created page with " InstructionWord.cc <PRE> // InstructionWord class // // #ifndef INSTRUCTIONWORD_CC #define INSTRUCTIONWORD_CC #ifndef MANO_H #include "mano.h" #endif #include <iostrea...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

InstructionWord.cc

//  InstructionWord class
//
//

#ifndef INSTRUCTIONWORD_CC
#define INSTRUCTIONWORD_CC

#ifndef MANO_H
  #include "mano.h"
#endif

#include <iostream.h>

class InstructionWord;

istream &operator >> (istream &IS, InstructionWord &v );

ostream &operator << (ostream &OS, InstructionWord &v );

class InstructionWord {

  unsigned short us_data;
  short s_Location;

friend ostream &operator << (ostream &OS, InstructionWord &v )
{
if( DEBUG )
cout << "Memory Cell: << 0 " << endl;

    unsigned short displaymask = Bitmask15;

    OS << v.s_Location << "    "; // tab space

    for (short i = 15; i > 0; i--)
    {
         OS << (v.us_data & displaymask ? 1 : 0);
         displaymask >>= 1;
    }

    OS << "    "; // separate bin and hex formats

    OS.setf( ios::hex );
    
    OS << v.us_data;
    
    OS.setf( ios::dec ); // hex output 

    OS << "    "; // separate hex and decimal formats

    OS << v.us_data; // decimal output
    
    OS << endl;
    return OS;
}

public:

InstructionWord()
{
   s_Location = 0;
   us_data = 0;
}

InstructionWord( const InstructionWord& v )
{
     s_Location = v.s_Location;
     us_data = v.us_data;
}

~InstructionWord(){}


InstructionWord operator = (const InstructionWord& v)
{
  s_Location = v.s_Location;
  us_data = v.us_data;
  return *this;
}

InstructionWord& operator = (const InstructionWord* v)
{
      s_Location = v->s_Location;
      us_data = v->us_data;
      return *this;
}

InstructionWord& operator = (const short s_v)
{
      us_data = s_v;
      return *this;
}

short operator== (const InstructionWord& v)
{
      return (s_Location == v.s_Location);
}
  
short operator < ( const InstructionWord& v)
{
      return (s_Location < v.s_Location);
}

short operator > ( const InstructionWord& v)
{
      return (s_Location > v.s_Location);
}

InstructionWord ADD( const InstructionWord& Q, short &s_Carry )
{
if( DEBUG )
cout << "Memory Cell: ADD 0 " << endl;

     InstructionWord v_Temp;
     int i_hold = us_data + Q.us_data + s_Carry;
     if ( i_hold > MaxShort )
        s_Carry = 1;
     else
        s_Carry = 0;
     v_Temp.us_data = i_hold;   
     return v_Temp;
}
  
InstructionWord AND( const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: AND 0 " << endl;

     InstructionWord v_Temp;
     v_Temp.us_data = us_data & Q.us_data;
     return v_Temp;
}


void buildpoint(InstructionWord *v)
{
      v->s_Location = s_Location;
      v->us_data = us_data;
}

short CellToDec(short i_range = 12)
{
if( DEBUG )
cout << "Memory Cell: CellToDec 0 " << endl;

      unsigned ui_Mask = 1;
      short i_Result = 0;
      for (short i = 0; i < i_range; i++)
      {
            i_Result = us_data & ui_Mask;
            ui_Mask <<= 1;
      }
      return i_Result;
}
  
void clear()
{
   s_Location = 0;
   us_data = 0;
}

void circulateleft ( short &E )
{
     unsigned short displaymask = 1 << 15;
     unsigned short ui_save = displaymask & us_data;
us_data << 1;

if ( E )
   us_data |= E;
else
   us_data &= 0;

if (ui_save)
   E = 1;
else
   E = 0;
}

void circulateright ( short &E )
{
unsigned displaymask = 1;
unsigned ui_save = displaymask & us_data;
us_data >> 1;

if ( E )
   us_data |= Bitmask15;
else
{
   unsigned short us_Temp = Bitmask15;
   ~us_Temp;
    us_data &= us_Temp;
}
if (ui_save)
   E = 1;
else
   E = 0;
}

void COMPLEMENT()
{
   ~us_data;
}

void decrement()
{
 us_data--;
}

void DecToCell( unsigned short s_Decimal )
{
   us_data = s_Decimal;
}

unsigned short getopcode()
{
if( DEBUG )
cout << "Memory Cell: getopcode 0 " << endl;

     short s_Result = 0;
     short s_Mask = 1 << 12;
     if( s_Mask & us_data )
         s_Result = 1;
     s_Mask << 1;
     if( s_Mask & us_data )
         s_Result += 2;
     s_Mask << 1;
     if( s_Mask & us_data )
         s_Result += 3;
     return s_Result;
}

unsigned short getRcode()
{
if( DEBUG )
cout << "Memory Cell: getRcode 0 " << endl;

  unsigned ui_Mask = Bitmask6;
  short s_Result = 0;
  for (short i = 0; i < 5; i++)
  {
        s_Result = us_data & ui_Mask;
        ui_Mask <<= 1;
  }
  return s_Result;
}

unsigned short getIcode()
{
if( DEBUG )
cout << "Memory Cell: getlcode 0 " << endl;

  short s_Result = Bitmask15;
  return s_Result & us_data;
}  

unsigned short gettag()
{
if( DEBUG )
cout << "Memory Cell: gettag 0 " << endl;

     return s_Location;
}

void increment()
{
if( DEBUG )
cout << "Memory Cell: increment 0 " << endl;

   us_data++;
}

InstructionWord NAND( const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: NAND 0 " << endl;

     InstructionWord v_Temp;
     v_Temp.us_data = us_data & Q.us_data;
     ~v_Temp.us_data;
     return v_Temp;
}

InstructionWord NOR(const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: NOR 0 " << endl;

     InstructionWord v_Temp;
     v_Temp.us_data = us_data | Q.us_data;
     ~v_Temp.us_data;
     return v_Temp;
}

InstructionWord OR(const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: OR 0 " << endl;

     InstructionWord v_Temp;
     v_Temp.us_data = us_data | Q.us_data;
     return v_Temp;
}


unsigned short returndata()
{
if( DEBUG )
cout << "Memory Cell: returndata 0 " << endl;

     return us_data;
}


void setlocation( int T )
{
if( DEBUG )
cout << "Memory Cell: setlocation 0 " << endl;

     s_Location = T;
}

void setdata( unsigned short US )
{
if( DEBUG )
cout << "Memory Cell: setdata 0 " << endl;

     us_data = US;
}

void shift_arithmetic_left()
{
if( DEBUG )
cout << "Memory Cell: shift_arithmetic_left 0 " << endl;

     unsigned displaymask = 1;
     unsigned ui_save = displaymask & us_data;
     us_data << 1;
     us_data &= ui_save;
}

void shift_arithmetic_right()
{
if( DEBUG )
cout << "Memory Cell: shift_arithmetic_right 0 " << endl;

     unsigned displaymask = 1 << 15;
     unsigned ui_save = displaymask & us_data;
     us_data >> 1;
     us_data &= ui_save;
}

void shift_circular_left()
{
if( DEBUG )
cout << "Memory Cell: shift_circular_left 0 " << endl;

     unsigned displaymask = 1 << 15;
     unsigned ui_save = displaymask & us_data;
     us_data << 1;
     ui_save >> 15;
     us_data &= ui_save;
}

void shift_circular_right()
{
if( DEBUG )
cout << "Memory Cell: shift_circular_right 0 " << endl;

     unsigned displaymask = 1;
     unsigned ui_save = displaymask & us_data;
     us_data >> 1;
     ui_save << 15;
     us_data = us_data & ui_save;
}

void shift_left()
{
if( DEBUG )
cout << "Memory Cell: shift_left 0 " << endl;

     us_data << 1;
}

void shift_right()
{
if( DEBUG )
cout << "Memory Cell: shift_right 0" << endl;

     us_data >> 1;
}

InstructionWord SUBTRACT( const InstructionWord& Q)
{
if( DEBUG )
cout << "Memory Cell: SUBTRACT 0 " << endl;

     InstructionWord v_Temp;
     unsigned short us_Temp = Q.us_data;
     ~us_Temp;
     v_Temp.us_data = us_data + us_Temp;
     return v_Temp;
}

void writecell(const InstructionWord& V, short i_range)
{
if( DEBUG )
cout << "Memory Cell: writecell 0 " << endl;

     unsigned displaymask = 1;
     for( unsigned i = 0; i < i_range; i++)
     {
          us_data = V.us_data & displaymask;
          displaymask << 1;
     }
}

InstructionWord XNOR( const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: XNOR 0 " << endl;

// exclusive NOR, equivalence
     InstructionWord v_Temp;
     return v_Temp;
}

InstructionWord XOR( const InstructionWord& Q )
{
if( DEBUG )
cout << "Memory Cell: XOR 0 " << endl;

     InstructionWord v_Temp;
     v_Temp.us_data = us_data ^ Q.us_data;
     return v_Temp;
}

};
#endif        // INSTRUCTIONWORD_CC

Internal Links

Parent Article: Mano PDP-8 Simulation Project Source Code