Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include "datatypes.h"
  5. #include "incrementAddr.h"
  6.  
  7.  
  8. using namespace std;
  9. void printingHeader(string memory, string progName, string startAddress) {
  10.     //1-4 location
  11.     cout << left << setw(4) << setfill(' ') << memory;
  12.     //5-8 4 spaces
  13.     cout << "    ";
  14.     //9-14 PROGNAME/Label
  15.     cout << left << setw(6) << setfill(' ') << progName;
  16.  
  17.     //15-17 3 spaces
  18.     cout << "   ";
  19.     //18-23 instructions
  20.     cout << "START ";
  21.     //24-26 3 spaces
  22.     cout << "   ";
  23.     //27-49 paramter
  24.     cout << left << setw(24) << setfill(' ') << startAddress;
  25.     //50-51 2 spaces
  26.     cout << "  ";
  27.  
  28.     //52-59+ machine instructions
  29.     cout << endl;
  30. }
  31.  
  32. void printingTextOrMod(string memory, string label, string instruction, string parameter) {
  33.     //1-4 location
  34.     cout << left << setw(4) << setfill(' ') << memory;
  35.     //5-8 4 spaces
  36.     cout << "    ";
  37.     //9-14 PROGNAME/Label
  38.     cout << left << setw(6) << setfill(' ') << label;
  39.     //15-16 2 spaces
  40.     cout << "  ";
  41.     //17 + or space
  42.     cout << " ";
  43.     //18-23 instructions
  44.     cout << left << setw(6) << setfill(' ') << instruction;
  45.     //24-25 2 spaces
  46.     cout << "  ";
  47.     //26 #,@,=,space
  48.     cout << " "; // for now
  49.     //27-49 paramter
  50.     cout << left << setw(24) << setfill(' ') << parameter;
  51.     //50-51 2 spaces
  52.     cout << "  ";
  53.     //52-59+ machine instructions
  54.     cout << endl;
  55. }
  56.  
  57. void printingEnd(string endAddress) {
  58.     //1-17 spaces
  59.     cout << "                 ";
  60.     //18-23 instructions
  61.     cout << "END   ";
  62.     //24-26 2 spaces
  63.     cout << "   ";
  64.     //27-49 paramter
  65.     cout << left << setw(24) << setfill(' ') << endAddress;
  66.     //50-51 2 spaces
  67.     cout << "  ";
  68.     //52-59+ machine instructions
  69.     cout << endl;
  70. }
  71.  
  72. int main() {
  73.     //HEADER EXAMPLE
  74.     string memoryH = "0000";
  75.     /*
  76.     string progname = "SUM";
  77.     string startingAddress = "0000";
  78.     */
  79.     //TEXT EXAMPLE
  80.     string memory = "0000";
  81.     string label = "LOOP";
  82.     string instrcution = "ADD";
  83.     string parameter = "TABLE";
  84.  
  85.  
  86.     string memory1 = "0000";
  87.     string label1 = "";
  88.     string instrcution1 = "TIX";
  89.     string parameter1 = "TABLE2";
  90.  
  91.  
  92.     //MODIFICATION EXAMPLE
  93.     string memory2 = "1720";
  94.     string label2 = "";
  95.     string instrcution2 = "RESW";
  96.     string parameter2 = "2000";
  97.  
  98.     headerRecord header;
  99.     textRecord text;
  100.     instruction instruct;
  101.     instruction instruct2;
  102.     instruction instruct3;
  103.  
  104.     instruct.opCode = "28";
  105.     instruct.format = 7;
  106.     instruct.mnemonic = "COMP";
  107.     instruct.disp = "61AF";
  108.  
  109.     instruct2.opCode = "24";
  110.     instruct2.format = 8;
  111.     instruct2.mnemonic = "DIV";
  112.     instruct2.disp = "62A5";
  113.  
  114.     instruct3.opCode = "D0";
  115.     instruct3.format = 5;
  116.     instruct3.mnemonic = "OP";
  117.     instruct3.disp = "25F3";
  118.  
  119.     text.instructions.push_back(instruct);
  120.     text.instructions.push_back(instruct2);
  121.     text.instructions.push_back(instruct3);
  122.  
  123.     //END EXAMPLE
  124.     string endAddress = "0000";
  125.  
  126.     printingHeader(memoryH, header.programName, header.startAddress);
  127.     //printingTextOrMod(text.startAddress, label, , parameter);
  128.     printingTextOrMod(memory1, label1, instrcution1, parameter1);
  129.     printingTextOrMod(memory2, label2, instrcution2, parameter2);
  130.     printingEnd(endAddress);
  131.  
  132.     text.startAddress = "0000";
  133.  
  134.  
  135.     //reference memory, check to see if we have label at this location
  136.     // print mnemonic
  137.    
  138.  
  139.     for (auto const& instruct : text.instructions) {
  140.         string findAddress = incrementAddr(text.startAddress, instruct.format);
  141.         text.startAddress = findAddress;
  142.         printingTextOrMod(findAddress,label,instruct.mnemonic, instruct.disp);
  143.  
  144.     }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement