From 618e4dd36101bb58683e9f6c500d2fd44b915820 Mon Sep 17 00:00:00 2001 From: "aljazbrodar." Date: Thu, 27 Nov 2025 14:53:37 +0100 Subject: [PATCH] Dodana obravnava tezav. --- ass2/simulator/machine.cpp | 11 +++++++ ass2/simulator/machine.h | 8 +++++ ass2/simulator/opcode.cpp | 63 +------------------------------------- ass2/simulator/opcode.h | 60 +++++++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 63 deletions(-) diff --git a/ass2/simulator/machine.cpp b/ass2/simulator/machine.cpp index b6d6cf1..c316ba3 100644 --- a/ass2/simulator/machine.cpp +++ b/ass2/simulator/machine.cpp @@ -94,6 +94,17 @@ void Machine::setDevice(int num, Device* device) { } +void Machine::notImplemented(string mnemonic) { + throw std::runtime_error("Instruction: " + mnemonic + " is not yet implemented."); +} + +void Machine::invalidOpcode(int opcode) { + throw std::runtime_error("Invalid opcode: " + to_string(opcode)); +} + +void Machine::invalidAddressing() { + throw std::runtime_error("Invalid addressing used."); +} diff --git a/ass2/simulator/machine.h b/ass2/simulator/machine.h index 02763f9..5c86b08 100644 --- a/ass2/simulator/machine.h +++ b/ass2/simulator/machine.h @@ -50,6 +50,14 @@ public: Device * getDevice(int num); void setDevice(int num, Device * device); + + void notImplemented(string mnemonic); + + // Izvajalnik je naletel na operacijsko kodo ukaza, ki ni veljavna. + void invalidOpcode(int opcode); + + // Neveljavno naslavljanje. + void invalidAddressing(); }; #endif diff --git a/ass2/simulator/opcode.cpp b/ass2/simulator/opcode.cpp index 388e32d..ccdab13 100644 --- a/ass2/simulator/opcode.cpp +++ b/ass2/simulator/opcode.cpp @@ -1,64 +1,3 @@ #include "opcode.h" -Opcode::Opcode() { -public: - static constexpr int ADD = 0x18; - static constexpr int ADDF = 0x58; - static constexpr int ADDR = 0x90; - static constexpr int AND = 0x40; - static constexpr int CLEAR = 0xB4; - static constexpr int COMP = 0x28; - static constexpr int COMPF = 0x88; - static constexpr int COMPR = 0xA0; - static constexpr int DIV = 0x24; - static constexpr int DIVF = 0x64; - static constexpr int DIVR = 0x9C; - static constexpr int FIX = 0xC4; - static constexpr int FLOAT = 0xC0; - static constexpr int HIO = 0xF4; - static constexpr int J = 0x3C; - static constexpr int JEQ = 0x30; - static constexpr int JGT = 0x34; - static constexpr int JLT = 0x38; - static constexpr int JSUB = 0x48; - static constexpr int LDA = 0x00; - static constexpr int LDB = 0x68; - static constexpr int LDCH = 0x50; - static constexpr int LDF = 0x70; - static constexpr int LDL = 0x08; - static constexpr int LDS = 0x6C; - static constexpr int LDT = 0x74; - static constexpr int LDX = 0x04; - static constexpr int LPS = 0xD0; - static constexpr int MUL = 0x20; - static constexpr int MULF = 0x60; - static constexpr int MULR = 0x98; - static constexpr int NORM = 0xC8; - static constexpr int OR = 0x44; - static constexpr int RD = 0xD8; - static constexpr int RMO = 0xAC; - static constexpr int RSUB = 0x4C; - static constexpr int SHIFTL = 0xA4; - static constexpr int SHIFTR = 0xA8; - static constexpr int SIO = 0xF0; - static constexpr int SSK = 0xEC; - static constexpr int STA = 0x0C; - static constexpr int STB = 0x78; - static constexpr int STCH = 0x54; - static constexpr int STF = 0x80; - static constexpr int STI = 0xD4; - static constexpr int STL = 0x14; - static constexpr int STS = 0x7C; - static constexpr int STSW = 0xE8; - static constexpr int STT = 0x84; - static constexpr int STX = 0x10; - static constexpr int SUB = 0x1C; - static constexpr int SUBF = 0x5C; - static constexpr int SUBR = 0x94; - static constexpr int SVC = 0xB0; - static constexpr int TD = 0xE0; - static constexpr int TIO = 0xF8; - static constexpr int TIX = 0x2C; - static constexpr int TIXR = 0xB8; - static constexpr int WD = 0xDC; -} +Opcode::Opcode() {} diff --git a/ass2/simulator/opcode.h b/ass2/simulator/opcode.h index 9b04fd3..9dc6f56 100644 --- a/ass2/simulator/opcode.h +++ b/ass2/simulator/opcode.h @@ -4,7 +4,65 @@ class Opcode { public: - Opcode(); + static constexpr int ADD = 0x18; + static constexpr int ADDF = 0x58; + static constexpr int ADDR = 0x90; + static constexpr int AND = 0x40; + static constexpr int CLEAR = 0xB4; + static constexpr int COMP = 0x28; + static constexpr int COMPF = 0x88; + static constexpr int COMPR = 0xA0; + static constexpr int DIV = 0x24; + static constexpr int DIVF = 0x64; + static constexpr int DIVR = 0x9C; + static constexpr int FIX = 0xC4; + static constexpr int FLOAT = 0xC0; + static constexpr int HIO = 0xF4; + static constexpr int J = 0x3C; + static constexpr int JEQ = 0x30; + static constexpr int JGT = 0x34; + static constexpr int JLT = 0x38; + static constexpr int JSUB = 0x48; + static constexpr int LDA = 0x00; + static constexpr int LDB = 0x68; + static constexpr int LDCH = 0x50; + static constexpr int LDF = 0x70; + static constexpr int LDL = 0x08; + static constexpr int LDS = 0x6C; + static constexpr int LDT = 0x74; + static constexpr int LDX = 0x04; + static constexpr int LPS = 0xD0; + static constexpr int MUL = 0x20; + static constexpr int MULF = 0x60; + static constexpr int MULR = 0x98; + static constexpr int NORM = 0xC8; + static constexpr int OR = 0x44; + static constexpr int RD = 0xD8; + static constexpr int RMO = 0xAC; + static constexpr int RSUB = 0x4C; + static constexpr int SHIFTL = 0xA4; + static constexpr int SHIFTR = 0xA8; + static constexpr int SIO = 0xF0; + static constexpr int SSK = 0xEC; + static constexpr int STA = 0x0C; + static constexpr int STB = 0x78; + static constexpr int STCH = 0x54; + static constexpr int STF = 0x80; + static constexpr int STI = 0xD4; + static constexpr int STL = 0x14; + static constexpr int STS = 0x7C; + static constexpr int STSW = 0xE8; + static constexpr int STT = 0x84; + static constexpr int STX = 0x10; + static constexpr int SUB = 0x1C; + static constexpr int SUBF = 0x5C; + static constexpr int SUBR = 0x94; + static constexpr int SVC = 0xB0; + static constexpr int TD = 0xE0; + static constexpr int TIO = 0xF8; + static constexpr int TIX = 0x2C; + static constexpr int TIXR = 0xB8; + static constexpr int WD = 0xDC; }; #endif // OPCODE_H