format3

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.5 kB
2
Indexable
Never
void dissem::format3Analysis(string bits) {

    string opCode = bits.substr(0, 2);
    string binOpCode = hexToBinary(opCode);
    string oldOpCode = binOpCode.substr(0, 6);
    string newOpCode = oldOpCode.append("00");
    opCode = binaryToHex(newOpCode); // determines opcode of mnemonic

    // finds matching mnemonic to opcode
    int mnemIndex = 0;
    for (int i = 0; i < 59; i++) {
        if (ops[i] == opCode) {
            mnemIndex = i;
        }
    }

    string curMnem = mnemonics[mnemIndex];


    string tmpBinNum = hexToBinary(bits.substr(0, 3));
    string nixbpe = tmpBinNum.substr(6, 11);

    string targetAdr = "";
    string targetSym = "";
    string disp = bits.substr(3, 3);
    string pc = addToAddr(currAddr, 3);

    if (nixbpe == "110010") {
        //simple pc
        targetAdr = addToAddr(disp, pc);

    } else if (nixbpe == "110100") {
        //simple base
        targetAdr = addToAddr(disp, base);

    } else if (nixbpe == "111000") {
        //simple x
        targetAdr = addToAddr(disp, xReg);
    } else if (nixbpe == "111010") {
        //simple x pc
        targetAdr = addToAddr(disp, pc);
        targetAdr = addToAddr(targetAdr, xReg);
    } else if (nixbpe == "111100") {
        //simple x b
        targetAdr = addToAddr(disp, base);
        targetAdr = addToAddr(targetAdr, xReg);
    } else if (nixbpe == "110000") {
        //simple abs
        targetAdr = disp;
    } else if (nixbpe == "010010") {
        //immediate pc
        targetAdr = addToAddr(disp, pc);
    } else if (nixbpe == "010100") {
        //immediate b
        targetAdr = addToAddr(disp, base);
    } else if (nixbpe == "010000") {
        //immediate abs
        targetAdr = disp;
    } else if (nixbpe == "100010") {
        //indirect pc
        targetAdr = addToAddr(disp, pc);
    } else if (nixbpe == "100100") {
        //indirect b
        targetAdr = addToAddr(disp, base);
    } else if (nixbpe == "100000") {
        //indirect abs
        targetAdr = disp;
    }

    if (targetSym == " ") {

        unsigned int disp = stoul(bits.substr(3, 5), nullptr, 16);
        targetSym = tempX + to_string(disp);

    }


       if (curMnem = "LDX") {
           xReg = stoul(targetAddr, nullptr, 16);

       }

       if (curMnem = "LDB") {
           targetSym = checkSymLit(targetAdr);
           base = targetAddr;
           output << setfill(' ') << left << setw(8) << "" << setw(10) << "" << setw(9) << "BASE" << setw(14) << targetSym << endl;
       }
       
    currAddr = addToAddr(currAddr, 3);
}