-
Notifications
You must be signed in to change notification settings - Fork 0
/
NEG.cpp
37 lines (24 loc) · 840 Bytes
/
NEG.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
#include "NEG.h"
NEG::NEG(string in1, string out): x(in1), j(out){}
void NEG::execute(int& i, DataMem& data)
{
if(!isdigit(x[0]))//checking if x is a variable
{
if(isdigit(j[0]))
throw invalid_argument("Second parameter has to be an address");//validating the syntax of the address
mtx.lock();
data.getRefData(j) = -1*data.getValData(x);//storing the negative value in the specified location
cout<<data.getValData(j)<<endl;
mtx.unlock();
}
else//if x is a constant
{
int var1 = stoi(x);//converting the string x into an int
if(isdigit(j[0]))
throw invalid_argument("Second parameter has to be an address");//validating the syntax of the address
mtx.lock();
data.getRefData(j) = -1*var1;//storing the negative value in the specified location
cout<<data.getValData(j)<<endl;
mtx.unlock();
}
}