added "beq" command
This commit is contained in:
@@ -7,8 +7,15 @@
|
||||
|
||||
#include "Memory.h"
|
||||
#include "Register.h"
|
||||
#include "../Manager.h"
|
||||
#include "../ProgramLoader.h"
|
||||
|
||||
void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
/// Falls die aktuelle Zeile ein Label ist, return
|
||||
if (const auto length = commandVector.at(0).size(); commandVector.at(0).at(length - 1) == ':') {
|
||||
return;
|
||||
}
|
||||
|
||||
/// Extrahiere den eigentlichen RISC-V Befehl für die ALU
|
||||
const std::string &command = commandVector.at(0);
|
||||
|
||||
@@ -21,7 +28,7 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
}
|
||||
/// Wandle Vektor[3] (das dritte Argument) nur um, falls dieser existiert
|
||||
int arg3 = 0;
|
||||
if (commandVector.size() > 3) {
|
||||
if (commandVector.size() > 3 && isdigit(commandVector.at(3).at(1))) {
|
||||
arg3 = parseArgument(commandVector.at(3));
|
||||
}
|
||||
|
||||
@@ -103,6 +110,14 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
const auto data = Register::getInstance().getRegister(arg1);
|
||||
/// Speichere die Daten im angegeben RAM slot
|
||||
Memory::getInstance()->store(address, data);
|
||||
} else if (command == "beq") {
|
||||
const auto register1 = Register::getInstance().getRegister(arg1);
|
||||
const auto register2 = Register::getInstance().getRegister(arg2);
|
||||
const auto &label = commandVector.at(3);
|
||||
const auto streamPos = ProgramLoader::getInstance()->getStreamPosition(label);
|
||||
if (register1 == register2) {
|
||||
Manager::getInstance()->setStreamPosition(streamPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user