-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmov.cpp
More file actions
50 lines (47 loc) · 1.24 KB
/
mov.cpp
File metadata and controls
50 lines (47 loc) · 1.24 KB
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
48
49
50
#include "library.h"
#include "tools.h"
extern int pc;
extern string reg[7],memory[65535];
void mov(string cmd[], int len)
{
if(len!=3)
{
cout<<"error : invlaid no. of args"<<endl;
}
else
{
if(!validRegister(cmd[1]) || !validRegister(cmd[2]))
cout<<"error : invalid register(s)"<<endl;
else
{
if(cmd[2]=="m" || cmd[1]=="m")
{
string addr;
int regNo;
if(cmd[2]=="m")
{
regNo=registerNumber(cmd[1]);
addr=reg[5]+reg[6];
int decAddr=hexToDec(addr);
reg[regNo]=memory[decAddr];
}
else
{
regNo=registerNumber(cmd[2]);
addr=reg[5]+reg[6];
int decAddr=hexToDec(addr);
memory[decAddr]=reg[regNo];
cout<<"memory["<<addr<<"] = "<<reg[regNo]<<endl;
}
}
else
{
int reg1,reg2;
reg1=registerNumber(cmd[1]);
reg2=registerNumber(cmd[2]);
string temp;
reg[reg1]=reg[reg2];
}
}
}
}