Dodal ukaze za format 3 in 4

This commit is contained in:
Timon 2025-11-30 20:19:41 +01:00
parent cf3dd766d0
commit 8222f8dd0a
4 changed files with 117 additions and 8 deletions

View file

@ -45,6 +45,50 @@ machine::machine() {
else setSW(CC_GT);
return true;}},
};
ukaziSICF3F4 = {
{"ADD", [&](int m){setA(getA()+getWord(m)); return true;}},
{"SUB", [&](int m){setA(getA()-getWord(m)); return true;}},
{"MUL", [&](int m){setA(getA()*getWord(m)); return true;}},
{"DIV", [&](int m){if(getWord(m) == 0) divisionByZero();setA(getA()/getWord(m)); return true;}},
{"AND", [&](int m){setA(getA()&getWord(m)); return true;}},
{"OR", [&](int m){setA(getA()|getWord(m)); return true;}},
{"COMP", [&](int m){int a = getA(); int b = getWord(m);
if (a < b) setSW(CC_LT);
else if (a == b) setSW(CC_EQ);
else setSW(CC_GT);
return true;}},
{"J", [&](int m){setPC(m); return true;}},
{"JEQ", [&](int m){if (getSW() == CC_EQ){setPC(m);}
else {setPC(getPC()+1);} return true;}},
{"JGT", [&](int m){if (getSW() == CC_GT) {setPC(m);}
else {setPC(getPC()+1);} return true;}},
{"JLT", [&](int m){if (getSW() == CC_LT){setPC(m);}
else{setPC(getPC()+1);} return true;}},
{"JSUB", [&](int m){setL(getPC()); setPC(m); return true;}},
{"RSUB", [&](int m){setPC(getL()); return true;}},
{"LDA", [&](int m){setA(getWord(m)); return true;}},
{"LDB", [&](int m){setB(getWord(m)); return true;}},
{"LDT", [&](int m){setT(getWord(m)); return true;}},
{"LDX", [&](int m){setX(getWord(m)); return true;}},
{"LDS", [&](int m){setS(getWord(m)); return true;}},
{"LDL", [&](int m){setL(getWord(m)); return true;}},
{"LDCH", [&](int m){setA(getByte(m)); return true;}}, //POPRAVIT
{"STA", [&](int m){setWord(m, getA()); return true;}},
{"STB", [&](int m){setWord(m, getB()); return true;}},
{"STT", [&](int m){setWord(m, getT()); return true;}},
{"STX", [&](int m){setWord(m, getX()); return true;}},
{"STL", [&](int m){setWord(m, getL()); return true;}},
{"STS", [&](int m){setWord(m, getS()); return true;}},
{"STCH", [&](int m){setByte(m, getA()); return true;}}, //POPRAVIT
{"TIX", [&](int m){setX(getX()+1);
if (getX() < getWord(m)) setSW(CC_LT);
else if (getX() == getWord(m)) setSW(CC_EQ);
else setSW(CC_GT);
return true;}},
{"WD", [&](int m){return true;}},//POPRAVIT
{"RD", [&](int m){return true;}},//POPRAVIT
};
}
//machine::getterji, setterji
@ -145,13 +189,6 @@ machine::machine() {
return 1;
}
/*void incompatibleArgument(const type_info& t1, const type_info& t2) {
stringstream ss;
ss << "Tipa vrednosti se razlikujeta: " << t1.name() << " vs " << t2.name();
throw invalid_argument(ss.str());
}*/
void machine::outOfMemoryRange(int memory) {
throw out_of_range("Naslov je izven pomnilniškega obmocja: " + to_string(memory));
}

View file

@ -37,6 +37,7 @@ private:
std::array<uint8_t, MAX_ADRESS> pomnilnik{};
std::array<std::unique_ptr<Device>, 256> naprave{};
std::unordered_map<std::string, std::function<bool(int,int)>> ukaziF2;
std::unordered_map<std::string, std::function<bool(int)>> ukaziSICF3F4;
public:
machine();
@ -61,7 +62,7 @@ public:
void setByte(int adr, int val);
int getWord(int adr);
void setWord(int adr, int val);
int getUN(int n, int x, int b, int p, int e, int operand);
// devices
Device& getDevice(uint8_t dev);
void setDevice(uint8_t num, std::unique_ptr<Device> dev);
@ -73,6 +74,7 @@ public:
void invalidAdressing();
void invalidRegister(const std::string& mnemonic, int r1, int r2);
void outOfMemoryRange(int mem);
void divisionByZero();
// execution
uint8_t fetch();