From 462dedbe722f5c7b6cea5bbde485f5bf5df19435 Mon Sep 17 00:00:00 2001 From: black Date: Tue, 8 Jul 2025 07:46:25 +0200 Subject: [PATCH] cpu argument fixes --- src/components/Alu.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/Alu.cpp b/src/components/Alu.cpp index c34b988..5ca47c6 100644 --- a/src/components/Alu.cpp +++ b/src/components/Alu.cpp @@ -3,8 +3,6 @@ // #include "Alu.h" - -#include #include #include "Memory.h" @@ -15,14 +13,16 @@ void Alu::calculate(const std::vector &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; }