-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.h
64 lines (53 loc) · 1.38 KB
/
validate.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef VALIDATE_H
#define VALIDATE_H
#include "header.h"
using namespace std;
/* Validate memory address to be in range from 0000 to FFFF */
bool validMemory(string address) {
if(address.length() != 4)
return false;
for(int i=0; i<4; i++) {
if((address[i] >= 'A' && address[i] <= 'F') || (address[i] >= '0' && address[i] <= '9'))
continue;
else
return false;
}
return true;
}
/* Validate data to be in range from 00 to FF */
bool validData(string data) {
if(data.length() != 2)
return false;
for(int i=0; i<2; i++) {
if((data[i] >= 'A' && data[i] <= 'F') || (data[i] >= '0' && data[i] <= '9'))
continue;
else
return false;
}
return true;
}
/* Validate register to be either A,B,C,D,E,H or L */
bool validRegister(string reg) {
if(reg == "A" || reg == "B" || reg == "C" || reg == "D" || reg == "E" || reg == "H" || reg == "L")
return true;
return false;
}
/* Validate type of operation type */
bool validateOperation(char op) {
switch(op) {
case 'm':
case 'l':
case 'b':
case 'a':
return true;
default:
return false;
}
}
/* Validate register pair */
bool validateRegisterPair(string reg) {
if(reg == "B" || reg == "D" || reg == "H")
return true;
return false;
}
#endif