Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include "datatypes.h"
- #include "incrementAddr.h"
- using namespace std;
- void printingHeader(string memory, string progName, string startAddress) {
- //1-4 location
- cout << left << setw(4) << setfill(' ') << memory;
- //5-8 4 spaces
- cout << " ";
- //9-14 PROGNAME/Label
- cout << left << setw(6) << setfill(' ') << progName;
- //15-17 3 spaces
- cout << " ";
- //18-23 instructions
- cout << "START ";
- //24-26 3 spaces
- cout << " ";
- //27-49 paramter
- cout << left << setw(24) << setfill(' ') << startAddress;
- //50-51 2 spaces
- cout << " ";
- //52-59+ machine instructions
- cout << endl;
- }
- void printingTextOrMod(string memory, string label, string instruction, string parameter) {
- //1-4 location
- cout << left << setw(4) << setfill(' ') << memory;
- //5-8 4 spaces
- cout << " ";
- //9-14 PROGNAME/Label
- cout << left << setw(6) << setfill(' ') << label;
- //15-16 2 spaces
- cout << " ";
- //17 + or space
- cout << " ";
- //18-23 instructions
- cout << left << setw(6) << setfill(' ') << instruction;
- //24-25 2 spaces
- cout << " ";
- //26 #,@,=,space
- cout << " "; // for now
- //27-49 paramter
- cout << left << setw(24) << setfill(' ') << parameter;
- //50-51 2 spaces
- cout << " ";
- //52-59+ machine instructions
- cout << endl;
- }
- void printingEnd(string endAddress) {
- //1-17 spaces
- cout << " ";
- //18-23 instructions
- cout << "END ";
- //24-26 2 spaces
- cout << " ";
- //27-49 paramter
- cout << left << setw(24) << setfill(' ') << endAddress;
- //50-51 2 spaces
- cout << " ";
- //52-59+ machine instructions
- cout << endl;
- }
- int main() {
- //HEADER EXAMPLE
- string memoryH = "0000";
- /*
- string progname = "SUM";
- string startingAddress = "0000";
- */
- //TEXT EXAMPLE
- string memory = "0000";
- string label = "LOOP";
- string instrcution = "ADD";
- string parameter = "TABLE";
- string memory1 = "0000";
- string label1 = "";
- string instrcution1 = "TIX";
- string parameter1 = "TABLE2";
- //MODIFICATION EXAMPLE
- string memory2 = "1720";
- string label2 = "";
- string instrcution2 = "RESW";
- string parameter2 = "2000";
- headerRecord header;
- textRecord text;
- instruction instruct;
- instruction instruct2;
- instruction instruct3;
- instruct.opCode = "28";
- instruct.format = 7;
- instruct.mnemonic = "COMP";
- instruct.disp = "61AF";
- instruct2.opCode = "24";
- instruct2.format = 8;
- instruct2.mnemonic = "DIV";
- instruct2.disp = "62A5";
- instruct3.opCode = "D0";
- instruct3.format = 5;
- instruct3.mnemonic = "OP";
- instruct3.disp = "25F3";
- text.instructions.push_back(instruct);
- text.instructions.push_back(instruct2);
- text.instructions.push_back(instruct3);
- //END EXAMPLE
- string endAddress = "0000";
- printingHeader(memoryH, header.programName, header.startAddress);
- //printingTextOrMod(text.startAddress, label, , parameter);
- printingTextOrMod(memory1, label1, instrcution1, parameter1);
- printingTextOrMod(memory2, label2, instrcution2, parameter2);
- printingEnd(endAddress);
- text.startAddress = "0000";
- //reference memory, check to see if we have label at this location
- // print mnemonic
- for (auto const& instruct : text.instructions) {
- string findAddress = incrementAddr(text.startAddress, instruct.format);
- text.startAddress = findAddress;
- printingTextOrMod(findAddress,label,instruct.mnemonic, instruct.disp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement