diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..027de22 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "cStandard": "c23", + "cppStandard": "c++23", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7c8d6eb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,55 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "sstream": "cpp" + } +} \ No newline at end of file diff --git a/ass2/machine.cpp b/ass2/machine.cpp index 7ed7724..6982dd6 100644 --- a/ass2/machine.cpp +++ b/ass2/machine.cpp @@ -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)); } diff --git a/ass2/machine.h b/ass2/machine.h index b483ee5..d9211a5 100644 --- a/ass2/machine.h +++ b/ass2/machine.h @@ -37,6 +37,7 @@ private: std::array pomnilnik{}; std::array, 256> naprave{}; std::unordered_map> ukaziF2; + std::unordered_map> 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 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();