-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMP.cpp
47 lines (45 loc) · 1.15 KB
/
CMP.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
40
41
42
43
44
45
46
47
#include "library.h"
#include "tools.h"
extern string reg[7],memory[65535];
extern int flag[5],pc;
void cmp(string cmd[], int len)
{
if(len!=2)
cout<<"error : "<<pc<<": invalid no. of args"<<endl;
else
{
if(validRegister(cmd[1])==0)
cout<<" error :"<<pc<<": invalid register"<<endl;
else
{
int num1,num2;
num1=hexToDec(reg[0]);
if(cmd[1]=="m")
{
string addr=reg[5]+reg[6];
int decAddr=hexToDec(addr);
string temp=memory[decAddr];
num2=hexToDec(temp);
}
else
{
num2=hexToDec(reg[registerNumber(cmd[1])]);
}
if(num1<num2)
{
flag[4]=1;
flag[1]=0;
}
else if(num1==num2)
{
flag[4]=0;
flag[1]=1;
}
else
{
flag[4]=0;
flag[1]=0;
}
}
}
}