cpu argument fixes
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
//
|
||||
|
||||
#include "Alu.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "Memory.h"
|
||||
@@ -15,14 +13,16 @@ void Alu::calculate(const std::vector<std::string> &commandVector) {
|
||||
const std::string &command = commandVector.at(0);
|
||||
|
||||
/// Extrahiere die Argumente des Befehls
|
||||
const auto arg1 = parseArgument(commandVector.at(0));
|
||||
const auto arg1 = parseArgument(commandVector.at(1));
|
||||
/// Wandle Vektor[2] (das zweite Argument) nur um, falls es kein SW/LW Argument ist
|
||||
int arg2 = 0;
|
||||
if (commandVector.at(1).find('(') != std::string::npos) {
|
||||
if (commandVector.at(2).find('(') != std::string::npos) {
|
||||
arg2 = parseArgument(commandVector.at(2));
|
||||
}
|
||||
/// Wandle Vektor[3] (das dritte Argument) nur um, falls dieser existiert
|
||||
int arg3 = 0;
|
||||
if (!commandVector.at(2).empty()) {
|
||||
arg3 = parseArgument(commandVector.at(2));
|
||||
if (!commandVector.at(3).empty()) {
|
||||
arg3 = parseArgument(commandVector.at(3));
|
||||
}
|
||||
|
||||
if (command == "add") {
|
||||
@@ -86,14 +86,15 @@ int Alu::parseArgument(std::string argument) {
|
||||
}
|
||||
|
||||
int Alu::parseAddress(const std::string &argument) {
|
||||
/// Trenne das Argument bei '('
|
||||
/// 0(x1)
|
||||
/// Finde die Position von '(', trenne die den String dort und
|
||||
/// addiere die umgewandelten Integer zur Adresse
|
||||
/// Bsp: 0(x1)
|
||||
const size_t pos = argument.find('(');
|
||||
if (pos != std::string::npos) {
|
||||
const auto immediate = argument.substr(0, pos);
|
||||
const auto register1 = argument.substr(pos + 1);
|
||||
const auto immediate = std::stoi(argument.substr(0, pos));
|
||||
const auto register1 = std::stoi(argument.substr(pos + 1));
|
||||
const auto address = immediate + register1;
|
||||
return std::stoi(address);
|
||||
return address;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user