"jal" command fixes

This commit is contained in:
black
2025-07-08 17:21:46 +02:00
parent f9bd85695a
commit 4fdaf3dafa
3 changed files with 23 additions and 2 deletions

View File

@@ -59,3 +59,15 @@ void Manager::init(const std::string &program_path) {
return;
}
}
std::streampos Manager::getNextStreamLineOffset() {
/// Speichert das aktuelle stream offset
const auto positionBefore = m_programFile.tellg();
/// Geht eine Zeile nach vorne zum nächsten Befehl (PC+4) und speichert den offset
std::string line;
std::getline(m_programFile, line);
const auto positionAfter = m_programFile.tellg();
/// Geht zum offset vom Anfang zurück und gibt die nächste Adresse (PC+4) zurück
m_programFile.seekg(positionBefore);
return positionAfter;
}

View File

@@ -67,6 +67,13 @@ public:
* @param program_path Der Pfad zur Quellcode .txt
*/
void init(const std::string &program_path);
/**
* Gibt das stream offset für den nächsten Befehl (PC+4) zurück
*
* @return Die stream offset Position ("Zeilennummer") des nächsten Befehls
*/
std::streampos getNextStreamLineOffset();
};

View File

@@ -130,12 +130,14 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
}
} else if (command == "jal") {
/// Jump and link Befehl
/// !!! Funktioniert nicht bei großen Daten aufgrund des casts des stream offsets zu int
const auto pos = static_cast<int>(Manager::getInstance()->getStreamPosition().operator std::streamoff());
/// !!! Aufgrund des casts des stream offsets zu int funktioniert das nicht bei großen Quellcode Dateien
/// und führt zu undefiniertem Verhalten !!!
const auto pos = static_cast<int>(Manager::getInstance()->getNextStreamLineOffset().operator std::streamoff());
const auto &label = commandVector.at(2);
const auto streamPos = ProgramLoader::getInstance()->getStreamPosition(label);
Register::getInstance().setRegister(arg1, pos);
Manager::getInstance()->setStreamPosition(streamPos);
} else if (command == "jalr") {
}
}