added "jal" command
This commit is contained in:
@@ -40,6 +40,10 @@ void Manager::setStreamPosition(const std::streampos pos) {
|
||||
m_programFile.seekg(pos);
|
||||
}
|
||||
|
||||
std::streampos Manager::getStreamPosition() {
|
||||
return m_programFile.tellg();
|
||||
}
|
||||
|
||||
void Manager::init(const std::string &program_path) {
|
||||
m_path = program_path;
|
||||
std::cout << "Öffne Quellcode Datei: '" << m_path << "'" << "\n" << std::flush;
|
||||
|
||||
@@ -54,6 +54,18 @@ public:
|
||||
*/
|
||||
void setStreamPosition(std::streampos pos);
|
||||
|
||||
/**
|
||||
* Gibt die aktuelle Position des Streams (virtuellen Lesekopfes) zurück
|
||||
*
|
||||
* @return Die Streamposition des Lesekopfes
|
||||
*/
|
||||
std::streampos getStreamPosition();
|
||||
|
||||
/**
|
||||
* Öffnet die Quellcodedatei
|
||||
*
|
||||
* @param program_path Der Pfad zur Quellcode .txt
|
||||
*/
|
||||
void init(const std::string &program_path);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
//
|
||||
|
||||
#include "Alu.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "Memory.h"
|
||||
@@ -126,6 +128,14 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
if (register1 != register2) {
|
||||
Manager::getInstance()->setStreamPosition(streamPos);
|
||||
}
|
||||
} 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());
|
||||
const auto &label = commandVector.at(2);
|
||||
const auto streamPos = ProgramLoader::getInstance()->getStreamPosition(label);
|
||||
Register::getInstance().setRegister(arg1, pos);
|
||||
Manager::getInstance()->setStreamPosition(streamPos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
* @param address Die Adresse, aus der der Wert gelesen werden soll
|
||||
* @return Der Wert aus der Adresse
|
||||
*/
|
||||
int load(int address) const;
|
||||
[[nodiscard]] int load(int address) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "Register.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
Register::Register() {
|
||||
m_registers = {0};
|
||||
@@ -15,6 +17,7 @@ Register &Register::getInstance() {
|
||||
}
|
||||
|
||||
void Register::setRegister(const int reg, const int value) {
|
||||
if (reg == 0) std::cerr << "Register 0 darf nicht beschrieben werden!";
|
||||
m_registers.at(reg) = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#ifndef REGISTER_H
|
||||
#define REGISTER_H
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
/// Eine Registerklasse als Singleton implementiert.
|
||||
/// Als Speicher (Registers) wird ein int Array genutzt.
|
||||
@@ -50,7 +51,7 @@ public:
|
||||
* @param reg Die Position des Registers
|
||||
* @return Der Wert des Registers
|
||||
*/
|
||||
int getRegister(int reg) const;
|
||||
[[nodiscard]] int getRegister(int reg) const;
|
||||
};
|
||||
|
||||
#endif //REGISTER_H
|
||||
|
||||
Reference in New Issue
Block a user