-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembler.h
75 lines (58 loc) · 1.91 KB
/
assembler.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
65
66
67
68
69
70
71
72
73
74
75
#ifndef ASSEMBLER_H
#define ASSEMBLER_H
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
// Class for symbol table
class SymbolTable {
private:
std::map<std::string, int> table;
public:
// Constructor & Destructor
SymbolTable();
~SymbolTable();
// Function to add a label and its corresponding address to the symbol table
void addLabel(const std::string &label, int address);
// Function to search for a label in the symbol table and return its address
int searchLabel(const std::string &label);
};
// Class for assembler
class Assembler {
private:
public:
static const int VAR = 0;
static const int JMP = 0;
static const int JRP = 1;
static const int LDN = 2;
static const int STO = 3;
static const int SUB = 4;
static const int CMP = 6;
static const int STP = 7;
static const int LDP = 8;
static const int ADD = 9;
static const int DIV = 10;
static const int MOD = 11;
static const int LAN = 12;
static const int LOR = 13;
static const int LNT = 14;
static const int SHL = 15;
static const int SHR = 16;
// Constructor & Destructor
Assembler();
~Assembler();
// Function to perform the assembly process, taking a SymbolTable and logging the process
static void assemble(const SymbolTable &table);
// Function to process the assemble language
static std::vector<std::string> processAssembleCode(SymbolTable table, std::vector<std::string> &log);
// Function to export binary code to a file
static void exportToFile(const std::vector<std::string> &binaryCode);
// Function to get the opcode corresponding to the instruction
static int getOpCode(const std::string &instruction);
// Function to export log messages to a file
static void exportToLog(const std::vector<std::string> &log);
};
#endif //ASSEMBLER_H