-
Notifications
You must be signed in to change notification settings - Fork 0
/
MUL.cpp
39 lines (26 loc) · 844 Bytes
/
MUL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "MUL.h"
MUL::MUL(string a, string b, string c): x(a), y(b), j(c){}
void MUL::execute(int& i, DataMem& data)
{
if(!isdigit(x[0]))//checking if x is a variable
{
if(isdigit(j[0]))
throw invalid_argument("Third parameter has to be an address");//validating the syntax of the address
mtx.lock();
data.getRefData(j) = data.getValData(x) * data.getValData(y);//storing the product of the two variables
cout<<data.getValData(j)<<endl;
mtx.unlock();
}
else//if x is a constant
{
int var1 = stoi(x);
int var2 = stoi(y);
if(isdigit(j[0]))
throw invalid_argument("Third parameter has to be an address");//validating the syntax of the address
mtx.lock();
data.getRefData(j) = var1 * var2;//storing the product of the two values
cout<<data.getValData(j)<<endl;
mtx.unlock();
}
}
MUL::~MUL(){}