-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler.cpp
More file actions
40 lines (34 loc) · 1014 Bytes
/
assembler.cpp
File metadata and controls
40 lines (34 loc) · 1014 Bytes
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
#include <QString>
#include <QRegExp>
#include <QDebug>
#include <iostream>
#include "assembler.h"
MatchTable::MatchTable(void)
{
registerPatternName.setPattern("^\\$([a-zA-Z]+\\d*)$");
registerPatternName.setCaseSensitivity(Qt::CaseInsensitive);
registerPatternNumber.setPattern("^\\$(\\d+)$");
}
int MatchTable::MatchInstruction(QString instruct)
{
for(int i=0;i<INSTRUCTIONSETSIZE;i++)
{
if(0==instruct.compare(coreInstructionSet[i].mnemonic)) return i;
}
return -1;
}
int MatchTable::MatchRegister(QString registerName)
{
registerName=registerName.toLower();
if(registerPatternNumber.indexIn(registerName)>=0)
return registerPatternNumber.capturedTexts()[1].toInt();
else if(registerPatternName.indexIn(registerName)>=0)
{
registerName=registerPatternName.capturedTexts()[1];
for(int i=0;i<REGISTERSETSIZE;i++)
{
if(0==registerName.compare(registerSet[i].name)) return i;
}
}
return -1;
}