Advertisement
Guest User

VirtualMachine.h

a guest
Apr 25th, 2011
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. /******************************************************************************
  2. Filename: VirtualMachine.h
  3. By: Matthew DeBord and Ronald Radut
  4. Created: 04/11/2011
  5. Last Modified: 04/20/2011
  6. Description: This header contains class declarations for the Virtual Machine
  7. ******************************************************************************/
  8.  
  9.  
  10. #include <cstdlib>  
  11. #include <iostream>
  12. #include <fstream>
  13. #include <string>
  14. #include <vector>
  15. #include <sstream>
  16. using namespace std;
  17.  
  18. // following format classes property of K Zemoudeh
  19. class format1 {
  20.     public:
  21.         unsigned UNUSED:6;
  22.         unsigned RS:2;
  23.         unsigned I:1;
  24.         unsigned RD:2;
  25.         unsigned OP:5;
  26.     };
  27. class format2 {
  28.     public:
  29.         unsigned ADDR:8;
  30.         unsigned I:1;
  31.         unsigned RD:2;
  32.         unsigned OP:5;
  33.     };
  34. class format3 {
  35.     public:
  36.         int CONST:8;
  37.         unsigned I:1;
  38.         unsigned RD:2;
  39.         unsigned OP:5;
  40.     };
  41. union instruction {
  42.         int i;
  43.         format1 f1;
  44.         format2 f2;
  45.         format3 f3;
  46.     };
  47.  
  48. // Begin Virtual Machine Class
  49. class VirtualMachine
  50. {
  51.             private:
  52.                 static const int REG_FILE_SIZE = 4;
  53.                 static const int MEM_SIZE = 256;
  54.                 vector<int> r;
  55.                 vector<int> mem;
  56.                 string line;
  57.                 unsigned int ir, pc, sr, sp, clock, base, limit;
  58.                
  59.                 //sign extender
  60.                 int signExtend(int i);
  61.  
  62.                 // following functions set the corresponding bit for the sr
  63.                 void setV(int i);
  64.                 void setL(int i);
  65.                 void setE(int i);
  66.                 void setG(int i);
  67.                 void setC(int i);
  68.  
  69.                 //following functions GET the corresponding bit from sr
  70.                 int getV();
  71.                 int getL();
  72.                 int getE();
  73.                 int getG();
  74.                 int getC();
  75.  
  76.                 bool checkOverflow(int a, int b);
  77.                 bool checkOverflow3(int a, int b, int c);
  78.                 bool checkOverflow1(int a);
  79.                 // need base/limit registers??  <--- ATTN <----
  80.  
  81.            public:
  82.                VirtualMachine();
  83.                void Execute();
  84.                
  85. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement