Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
PDP8-Simulator - myLib.cc

myLib.cc

Caricato da: Matthew
Scarica il programma completo

  1. /*
  2.  * myLib.cc
  3.  *
  4.  *  Created on: Mar 17, 2010
  5.  *      Author: matthew
  6.  */
  7.  
  8. #include <string>
  9. #include <vector>
  10.  
  11. #include "myLib.h"
  12.  
  13. void show_report(vector<message> &msg)
  14. {
  15.         cout<<endl<<"COMPILING REPORT:"<<endl;
  16.         cout<<"--------------------------------------------------------------------"<<endl;
  17.         if(msg.size()==0)
  18.                 cout<<"Compiled successfully!"<<endl;
  19.         for(int a=0; a<msg.size(); a++)
  20.         {
  21.                 cout<<"ERROR at line "<<msg[a].line<<": "<<msg[a].text<<endl;
  22.         }
  23.         cout<<"--------------------------------------------------------------------"<<endl;
  24. }
  25.  
  26. void debug_message(string msg)
  27. {
  28.         cout<<"[Debug Message] "<<msg<<endl;
  29. }
  30.  
  31. void error(string msg)
  32. {
  33.         cout<<"[Fatal Error] "<<msg<<endl;
  34. }
  35.  
  36. void c_error(vector<message> &report, int line, string text)
  37. {
  38.         message msg;
  39.         msg.line=line;
  40.         msg.text=text;
  41.         report.push_back(msg);
  42. }
  43.  
  44. int bit_4(int source, int dest)
  45. {
  46.         if(dest/128==source/128)
  47.         {
  48.                 return 1;
  49.         }
  50.         else if(dest/128==0)
  51.         {
  52.                 return 0;
  53.         }
  54.         else
  55.         {
  56.                 return -1;
  57.         }
  58. }
  59.  
  60. string binary(int dec)
  61. {
  62.         string res;
  63.         while(dec>0)
  64.         {
  65.                 if(dec%2==1)res.insert(res.begin(),'1');
  66.                 else res.insert(res.begin(),'0');
  67.                 dec/=2;
  68.         }
  69.         while(res.size()<7)
  70.         {
  71.                 res.insert(res.begin(),'0');
  72.         }
  73.         return res;
  74. }