forked from mashiox/idaho_sicxe_assembler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopcodetab.h
59 lines (47 loc) · 1.67 KB
/
opcodetab.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
/* Shad Aziz, Phillip Domann, Melanie Reed, Matt Walther
mascxxxx
Team Idaho
prog2
CS530, Spring 2016
*/
#ifndef OPCODETAB_H
#define OPCODETAB_H
#include <map>
#include "opcode_error_exception.h"
using namespace std;
class opcodetab {
public:
// ctor
// creates a new dictionary structure and loads all of the opcodes for
// the SIC/XE architecture into the table. Use the STL
// map for this.
opcodetab();
// takes a SIC/XE opcode and returns the machine code
// equivalent as a two byte string in hexadecimal.
// Example: get_machine_code("ADD") returns the value 18
// Note that opcodes may be prepended with a '+'.
// throws an opcode_error_exception if the opcode is not
// found in the table.
string get_machine_code(string);
// takes a SIC/XE opcode and returns the number of bytes
// needed to encode the instruction, which is an int in
// the range 1..4.
// NOTE: the opcode must be prepended with a '+' for format 4.
// throws an opcode_error_exception if the opcode is not
// found in the table.
int get_instruction_size(string);
// instruction menmonic and details pair
struct instr {
string menmonic;
struct details {
short format;
string opcode;
} details;
};
// instruction array to load map
static const struct instr instrs[59];
private:
// instruction map
map<string, struct instr::details> opcodeTab;
};
#endif